@simplybusiness/mobius 3.1.1 → 3.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -2
- package/dist/cjs/components/Accordion/Accordion.d.ts +2 -2
- package/dist/cjs/components/Alert/Alert.d.ts +2 -2
- package/dist/cjs/components/Box/Box.d.ts +2 -2
- package/dist/cjs/components/Breadcrumbs/BreadcrumbItem.d.ts +2 -2
- package/dist/cjs/components/Breadcrumbs/Breadcrumbs.d.ts +2 -2
- package/dist/cjs/components/Button/Button.d.ts +4 -4
- package/dist/cjs/components/Checkbox/Checkbox.test.js +9 -3
- package/dist/cjs/components/Checkbox/Checkbox.test.js.map +1 -1
- package/dist/cjs/components/Checkbox/CheckboxItem.js +3 -1
- package/dist/cjs/components/Checkbox/CheckboxItem.js.map +1 -1
- package/dist/cjs/components/Checkbox/types.d.ts +4 -4
- package/dist/cjs/components/Chopin/Actions/Actions.d.ts +2 -2
- package/dist/cjs/components/Chopin/Footer/types.d.ts +1 -1
- package/dist/cjs/components/Chopin/Header/mockOpeningHoursData.d.ts +1 -1
- package/dist/cjs/components/Chopin/PercentageTotalsQuestion/PercentageItem.d.ts +1 -1
- package/dist/cjs/components/Chopin/PercentageTotalsQuestion/PercentageTotalsQuestion.d.ts +1 -1
- package/dist/cjs/components/Chopin/Question/Question.d.ts +2 -1
- package/dist/cjs/components/Chopin/Question/Question.js +2 -2
- package/dist/cjs/components/Chopin/Question/Question.js.map +1 -1
- package/dist/cjs/components/Chopin/Question/Question.test.js +22 -0
- package/dist/cjs/components/Chopin/Question/Question.test.js.map +1 -1
- package/dist/cjs/components/Chopin/QuestionGroup/QuestionGroup.d.ts +2 -2
- package/dist/cjs/components/Chopin/QuestionHelp/QuestionHelp.d.ts +2 -1
- package/dist/cjs/components/Chopin/QuestionHelp/QuestionHelp.js +4 -3
- package/dist/cjs/components/Chopin/QuestionHelp/QuestionHelp.js.map +1 -1
- package/dist/cjs/components/Chopin/Section/Section.d.ts +2 -2
- package/dist/cjs/components/Chopin/Steps/StepItem.d.ts +2 -2
- package/dist/cjs/components/Chopin/Steps/Steps.d.ts +2 -2
- package/dist/cjs/components/Chopin/Testimonial/Testimonial.d.ts +2 -2
- package/dist/cjs/components/Chopin/TradeSelector/ListBox/ListBox.d.ts +1 -1
- package/dist/cjs/components/Chopin/TradeSelector/ListBox/Option.d.ts +1 -1
- package/dist/cjs/components/Chopin/TradeSelector/Popover/Popover.d.ts +1 -1
- package/dist/cjs/components/Chopin/TradeSelector/SearchResults/SearchResults.d.ts +1 -1
- package/dist/cjs/components/Chopin/TradeSelector/SelectedTrade/SelectedTrade.d.ts +1 -1
- package/dist/cjs/components/Chopin/TradeSelector/TradeSelector.d.ts +2 -2
- package/dist/cjs/components/Chopin/TradeSelector/getItemsToDisplay/getItemsToDisplay.d.ts +1 -1
- package/dist/cjs/components/Chopin/TradeSelector/types.d.ts +5 -5
- package/dist/cjs/components/Container/Container.d.ts +2 -2
- package/dist/cjs/components/DataTable/FlexLayout.d.ts +1 -1
- package/dist/cjs/components/DataTable/SortIcon.d.ts +1 -1
- package/dist/cjs/components/DataTable/types.d.ts +5 -5
- package/dist/cjs/components/DatePicker/CalendarButton.d.ts +2 -2
- package/dist/cjs/components/DatePicker/DatePicker.d.ts +1 -1
- package/dist/cjs/components/DropdownMenu/DropdownMenu.d.ts +2 -2
- package/dist/cjs/components/DropdownMenu/Item.d.ts +2 -2
- package/dist/cjs/components/Fieldset/Fieldset.d.ts +3 -3
- package/dist/cjs/components/Flex/Flex.d.ts +2 -2
- package/dist/cjs/components/Grid/Grid.d.ts +2 -2
- package/dist/cjs/components/Grid/Item.d.ts +2 -2
- package/dist/cjs/components/Icon/types.d.ts +1 -1
- package/dist/cjs/components/Image/Image.d.ts +2 -2
- package/dist/cjs/components/Label/Label.d.ts +3 -3
- package/dist/cjs/components/Link/Link.d.ts +2 -2
- package/dist/cjs/components/List/List.d.ts +3 -3
- package/dist/cjs/components/List/ListItem.d.ts +2 -2
- package/dist/cjs/components/LoadingIndicator/LoadingIndicator.d.ts +1 -1
- package/dist/cjs/components/Modal/Content.d.ts +2 -2
- package/dist/cjs/components/Modal/Header.d.ts +2 -2
- package/dist/cjs/components/Modal/Modal.d.ts +1 -1
- package/dist/cjs/components/NumberField/NumberField.d.ts +2 -2
- package/dist/cjs/components/Option/Option.d.ts +1 -1
- package/dist/cjs/components/PasswordField/PasswordField.d.ts +1 -1
- package/dist/cjs/components/Progress/Progress.d.ts +2 -2
- package/dist/cjs/components/Radio/Radio.d.ts +2 -2
- package/dist/cjs/components/Radio/RadioButton.d.ts +2 -2
- package/dist/cjs/components/Radio/RadioGroup.d.ts +2 -2
- package/dist/cjs/components/SVG/SVG.d.ts +1 -1
- package/dist/cjs/components/Select/Select.d.ts +2 -2
- package/dist/cjs/components/Table/Body.d.ts +1 -1
- package/dist/cjs/components/Table/Cell.d.ts +1 -1
- package/dist/cjs/components/Table/Foot.d.ts +1 -1
- package/dist/cjs/components/Table/Head.d.ts +1 -1
- package/dist/cjs/components/Table/HeaderCell.d.ts +1 -1
- package/dist/cjs/components/Table/Row.d.ts +1 -1
- package/dist/cjs/components/Table/Table.d.ts +2 -2
- package/dist/cjs/components/Text/Text.d.ts +4 -4
- package/dist/cjs/components/TextArea/TextArea.d.ts +2 -2
- package/dist/cjs/components/TextAreaInput/TextAreaInput.d.ts +2 -2
- package/dist/cjs/components/TextField/TextField.d.ts +2 -2
- package/dist/cjs/components/Title/Title.d.ts +2 -2
- package/dist/cjs/contexts/ThemeContext/ThemeContext.d.ts +2 -2
- package/dist/cjs/hooks/useBreakpoint/useBreakpoint.d.ts +1 -1
- package/dist/cjs/types/components.d.ts +1 -1
- package/dist/cjs/types/icon.d.ts +1 -1
- package/dist/cjs/types/size.d.ts +1 -1
- package/dist/esm/components/Checkbox/Checkbox.test.js +10 -4
- package/dist/esm/components/Checkbox/Checkbox.test.js.map +1 -1
- package/dist/esm/components/Checkbox/CheckboxItem.js +3 -1
- package/dist/esm/components/Checkbox/CheckboxItem.js.map +1 -1
- package/dist/esm/components/Chopin/Question/Question.js +2 -2
- package/dist/esm/components/Chopin/Question/Question.js.map +1 -1
- package/dist/esm/components/Chopin/Question/Question.test.js +22 -0
- package/dist/esm/components/Chopin/Question/Question.test.js.map +1 -1
- package/dist/esm/components/Chopin/QuestionHelp/QuestionHelp.js +4 -3
- package/dist/esm/components/Chopin/QuestionHelp/QuestionHelp.js.map +1 -1
- package/dist/mobius.d.ts +3 -2
- package/package.json +1 -1
- package/src/components/Checkbox/Checkbox.story.mdx +25 -0
- package/src/components/Checkbox/Checkbox.test.tsx +15 -5
- package/src/components/Checkbox/CheckboxGroup.story.mdx +36 -0
- package/src/components/Checkbox/CheckboxItem.tsx +2 -0
- package/src/components/Chopin/Question/Question.story.mdx +128 -2
- package/src/components/Chopin/Question/Question.test.tsx +46 -0
- package/src/components/Chopin/Question/Question.tsx +7 -1
- package/src/components/Chopin/QuestionHelp/QuestionHelp.tsx +5 -2
- package/src/components/DatePicker/DatePicker.tsx +1 -1
- package/src/components/Radio/Radio.story.mdx +34 -0
- package/src/components/Radio/RadioButton.story.mdx +32 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useState } from "react";
|
|
2
2
|
import { Meta, ArgsTable, Canvas, Story } from "@storybook/addon-docs";
|
|
3
|
+
import styled from "@emotion/styled";
|
|
3
4
|
import { ThemeContext } from "../../../contexts";
|
|
4
5
|
import { Question } from "./Question";
|
|
5
6
|
import { Box } from "../../Box";
|
|
@@ -80,6 +81,7 @@ import { Chopin } from "@simplybusiness/mobius";
|
|
|
80
81
|
name="Normal"
|
|
81
82
|
args={{
|
|
82
83
|
label: "Question label",
|
|
84
|
+
closeHelpOnOutsideClick: false,
|
|
83
85
|
children: <TextField />,
|
|
84
86
|
}}
|
|
85
87
|
>
|
|
@@ -101,6 +103,7 @@ import { Chopin } from "@simplybusiness/mobius";
|
|
|
101
103
|
label: "Question label",
|
|
102
104
|
description:
|
|
103
105
|
"lorem ipsum dolor sit amet consectetur adipisicing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua",
|
|
106
|
+
closeHelpOnOutsideClick: false,
|
|
104
107
|
children: <TextField />,
|
|
105
108
|
}}
|
|
106
109
|
>
|
|
@@ -117,6 +120,7 @@ import { Chopin } from "@simplybusiness/mobius";
|
|
|
117
120
|
<li>Item Two</li>
|
|
118
121
|
</ul>
|
|
119
122
|
),
|
|
123
|
+
closeHelpOnOutsideClick: false,
|
|
120
124
|
children: <TextField />,
|
|
121
125
|
}}
|
|
122
126
|
>
|
|
@@ -147,6 +151,7 @@ import { Chopin } from "@simplybusiness/mobius";
|
|
|
147
151
|
),
|
|
148
152
|
description:
|
|
149
153
|
"You're required by law to have this cover if you have people working for you.",
|
|
154
|
+
closeHelpOnOutsideClick: false,
|
|
150
155
|
}}
|
|
151
156
|
>
|
|
152
157
|
{args => <Question {...args} />}
|
|
@@ -163,7 +168,7 @@ import { Chopin } from "@simplybusiness/mobius";
|
|
|
163
168
|
```
|
|
164
169
|
|
|
165
170
|
<Story
|
|
166
|
-
name="With Help
|
|
171
|
+
name="With Help Text"
|
|
167
172
|
args={{
|
|
168
173
|
label: "Question label",
|
|
169
174
|
help: (
|
|
@@ -178,6 +183,7 @@ import { Chopin } from "@simplybusiness/mobius";
|
|
|
178
183
|
</p>
|
|
179
184
|
</>
|
|
180
185
|
),
|
|
186
|
+
closeHelpOnOutsideClick: false,
|
|
181
187
|
children: <TextField />,
|
|
182
188
|
}}
|
|
183
189
|
>
|
|
@@ -188,6 +194,123 @@ import { Chopin } from "@simplybusiness/mobius";
|
|
|
188
194
|
```jsx
|
|
189
195
|
import { Chopin } from "@simplybusiness/mobius";
|
|
190
196
|
|
|
197
|
+
<Chopin.Question
|
|
198
|
+
help={
|
|
199
|
+
<>
|
|
200
|
+
<p>
|
|
201
|
+
This is a sample help text to demonstrate what help blocks look like in
|
|
202
|
+
questions.
|
|
203
|
+
</p>
|
|
204
|
+
<p>
|
|
205
|
+
This is a second paragraph to show that help texts aren't limited to
|
|
206
|
+
simple strings.
|
|
207
|
+
</p>
|
|
208
|
+
</>
|
|
209
|
+
}
|
|
210
|
+
label="Question label"
|
|
211
|
+
// Remove the prop if clicking outside the help text container should not close it
|
|
212
|
+
closeHelpOnOutsideClick
|
|
213
|
+
>
|
|
214
|
+
<TextField />
|
|
215
|
+
</Chopin.Question>
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
```css
|
|
219
|
+
/* Ensure `<Question />` width leaves enough space for help text to appear */
|
|
220
|
+
:root,
|
|
221
|
+
:host {
|
|
222
|
+
--question-desktop-width: calc(
|
|
223
|
+
100% - var(--chopin__help-content-width) - var(--chopin__help-content-margin)
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/* Position help text to the right of `<Question />` when on desktop */
|
|
228
|
+
.chopin\/QuestionHelp.--is-desktop .chopin\/QuestionHelpContent {
|
|
229
|
+
position: absolute;
|
|
230
|
+
top: 0;
|
|
231
|
+
right: calc(
|
|
232
|
+
0px - var(--chopin__help-content-width) - var(--chopin__help-content-margin)
|
|
233
|
+
);
|
|
234
|
+
width: var(--chopin__help-content-width);
|
|
235
|
+
margin: 0;
|
|
236
|
+
|
|
237
|
+
&::before {
|
|
238
|
+
box-sizing: border-box;
|
|
239
|
+
position: absolute;
|
|
240
|
+
top: 22px;
|
|
241
|
+
content: "";
|
|
242
|
+
display: block;
|
|
243
|
+
width: var(--chopin__help_content-arrow-size);
|
|
244
|
+
height: var(--chopin__help_content-arrow-size);
|
|
245
|
+
background-color: var(--color-background-highlight);
|
|
246
|
+
border: var(--size-border-width) solid var(--question-help-border-color);
|
|
247
|
+
transform: rotate(45deg);
|
|
248
|
+
left: calc(0px - (var(--chopin__help_content-arrow-size) / 2));
|
|
249
|
+
clip-path: polygon(0 0, 0% 100%, 100% 100%);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
export const QuestionContainer = styled("div")`
|
|
255
|
+
--question-desktop-width: calc(
|
|
256
|
+
100% - var(--chopin__help-content-width) - var(--chopin__help-content-margin)
|
|
257
|
+
);
|
|
258
|
+
.chopin\\/QuestionHelp.--is-desktop .chopin\\/QuestionHelpContent {
|
|
259
|
+
position: absolute;
|
|
260
|
+
top: 0;
|
|
261
|
+
right: calc(
|
|
262
|
+
0px - var(--chopin__help-content-width) - var(--chopin__help-content-margin)
|
|
263
|
+
);
|
|
264
|
+
width: var(--chopin__help-content-width);
|
|
265
|
+
margin: 0;
|
|
266
|
+
&::before {
|
|
267
|
+
box-sizing: border-box;
|
|
268
|
+
position: absolute;
|
|
269
|
+
top: 22px;
|
|
270
|
+
content: "";
|
|
271
|
+
display: block;
|
|
272
|
+
width: var(--chopin__help_content-arrow-size);
|
|
273
|
+
height: var(--chopin__help_content-arrow-size);
|
|
274
|
+
background-color: var(--color-background-highlight);
|
|
275
|
+
border: var(--size-border-width) solid var(--question-help-border-color);
|
|
276
|
+
transform: rotate(45deg);
|
|
277
|
+
left: calc(0px - (var(--chopin__help_content-arrow-size) / 2));
|
|
278
|
+
clip-path: polygon(0 0, 0% 100%, 100% 100%);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
`;
|
|
282
|
+
|
|
283
|
+
<Story
|
|
284
|
+
name="With Help Text Outside"
|
|
285
|
+
args={{
|
|
286
|
+
label: "Question label",
|
|
287
|
+
help: (
|
|
288
|
+
<>
|
|
289
|
+
<p>
|
|
290
|
+
This is a sample help text to demonstrate what help blocks look like
|
|
291
|
+
in questions.
|
|
292
|
+
</p>
|
|
293
|
+
<p>
|
|
294
|
+
This is a second paragraph to show that help texts aren't limited to
|
|
295
|
+
simple strings.
|
|
296
|
+
</p>
|
|
297
|
+
</>
|
|
298
|
+
),
|
|
299
|
+
closeHelpOnOutsideClick: true,
|
|
300
|
+
children: <TextField />,
|
|
301
|
+
}}
|
|
302
|
+
>
|
|
303
|
+
{args => (
|
|
304
|
+
<QuestionContainer>
|
|
305
|
+
<Question {...args} />
|
|
306
|
+
</QuestionContainer>
|
|
307
|
+
)}
|
|
308
|
+
</Story>
|
|
309
|
+
|
|
310
|
+
<!-- prettier-ignore -->
|
|
311
|
+
```jsx
|
|
312
|
+
import { Chopin } from "@simplybusiness/mobius";
|
|
313
|
+
|
|
191
314
|
<Chopin.Question
|
|
192
315
|
help={
|
|
193
316
|
<>
|
|
@@ -214,11 +337,13 @@ import { Chopin } from "@simplybusiness/mobius";
|
|
|
214
337
|
children: <TextField />,
|
|
215
338
|
errorMessage: "This field is required",
|
|
216
339
|
validationState: "invalid",
|
|
340
|
+
closeHelpOnOutsideClick: false,
|
|
217
341
|
}}
|
|
218
342
|
>
|
|
219
343
|
{args => <Question {...args} />}
|
|
220
344
|
</Story>
|
|
221
345
|
|
|
346
|
+
<!-- prettier-ignore -->
|
|
222
347
|
```jsx
|
|
223
348
|
import { Chopin } from "@simplybusiness/mobius";
|
|
224
349
|
|
|
@@ -228,7 +353,7 @@ import { Chopin } from "@simplybusiness/mobius";
|
|
|
228
353
|
validationState="invalid"
|
|
229
354
|
>
|
|
230
355
|
<TextField />
|
|
231
|
-
</Chopin.Question
|
|
356
|
+
</Chopin.Question>
|
|
232
357
|
```
|
|
233
358
|
|
|
234
359
|
<Story
|
|
@@ -252,6 +377,7 @@ import { Chopin } from "@simplybusiness/mobius";
|
|
|
252
377
|
),
|
|
253
378
|
errorMessage: "This field is required",
|
|
254
379
|
validationState: "invalid",
|
|
380
|
+
closeHelpOnOutsideClick: false,
|
|
255
381
|
}}
|
|
256
382
|
>
|
|
257
383
|
{args => <Question {...args} />}
|
|
@@ -5,6 +5,8 @@ import { Question } from ".";
|
|
|
5
5
|
import { TextField } from "../../TextField";
|
|
6
6
|
|
|
7
7
|
const WRAPPER_CLASS_NAME = "chopin/Question";
|
|
8
|
+
const OPEN_CLASS_NAME = "--is-open";
|
|
9
|
+
const CLOSED_CLASS_NAME = "--is-closed";
|
|
8
10
|
|
|
9
11
|
expect.extend(matchers);
|
|
10
12
|
|
|
@@ -170,5 +172,49 @@ describe("Question", () => {
|
|
|
170
172
|
await userEvent.keyboard("{escape}");
|
|
171
173
|
expect(screen.queryByRole("tooltip")).not.toBeInTheDocument();
|
|
172
174
|
});
|
|
175
|
+
|
|
176
|
+
describe("given closeHelpOnOutsideClick is set to true", () => {
|
|
177
|
+
it("should close on outside click", async () => {
|
|
178
|
+
const { container } = render(
|
|
179
|
+
<Question
|
|
180
|
+
label="Question"
|
|
181
|
+
help="This is a help message"
|
|
182
|
+
closeHelpOnOutsideClick
|
|
183
|
+
>
|
|
184
|
+
<TextField />
|
|
185
|
+
</Question>,
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
const toggle = screen.getByRole("button");
|
|
189
|
+
|
|
190
|
+
await userEvent.click(toggle);
|
|
191
|
+
|
|
192
|
+
expect(toggle.parentElement).toHaveClass(OPEN_CLASS_NAME);
|
|
193
|
+
|
|
194
|
+
await userEvent.click(container);
|
|
195
|
+
|
|
196
|
+
expect(toggle.parentElement).toHaveClass(CLOSED_CLASS_NAME);
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
describe("given closeHelpOnOutsideClick is not set", () => {
|
|
201
|
+
it("should close on outside click", async () => {
|
|
202
|
+
const { container } = render(
|
|
203
|
+
<Question label="Question" help="This is a help message">
|
|
204
|
+
<TextField />
|
|
205
|
+
</Question>,
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
const toggle = screen.getByRole("button");
|
|
209
|
+
|
|
210
|
+
await userEvent.click(toggle);
|
|
211
|
+
|
|
212
|
+
expect(toggle.parentElement).toHaveClass(OPEN_CLASS_NAME);
|
|
213
|
+
|
|
214
|
+
await userEvent.click(container);
|
|
215
|
+
|
|
216
|
+
expect(toggle.parentElement).toHaveClass(OPEN_CLASS_NAME);
|
|
217
|
+
});
|
|
218
|
+
});
|
|
173
219
|
});
|
|
174
220
|
});
|
|
@@ -21,6 +21,7 @@ export interface QuestionProps {
|
|
|
21
21
|
validationState?: "valid" | "invalid" | "";
|
|
22
22
|
help?: ReactNode;
|
|
23
23
|
className?: string;
|
|
24
|
+
closeHelpOnOutsideClick?: boolean;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
export function Question({
|
|
@@ -31,6 +32,7 @@ export function Question({
|
|
|
31
32
|
validationState,
|
|
32
33
|
help,
|
|
33
34
|
className,
|
|
35
|
+
closeHelpOnOutsideClick,
|
|
34
36
|
}: QuestionProps) {
|
|
35
37
|
const [isOpen, setIsOpen] = useState(false);
|
|
36
38
|
const labelId = useId();
|
|
@@ -72,7 +74,11 @@ export function Question({
|
|
|
72
74
|
{label}
|
|
73
75
|
</Label>
|
|
74
76
|
{help && (
|
|
75
|
-
<QuestionHelp
|
|
77
|
+
<QuestionHelp
|
|
78
|
+
onChange={handleChange}
|
|
79
|
+
isDesktop={isDesktop}
|
|
80
|
+
closeHelpOnOutsideClick={closeHelpOnOutsideClick}
|
|
81
|
+
>
|
|
76
82
|
{help}
|
|
77
83
|
</QuestionHelp>
|
|
78
84
|
)}
|
|
@@ -9,6 +9,7 @@ export interface QuestionHelpProps {
|
|
|
9
9
|
children: ReactNode;
|
|
10
10
|
onChange?: (state: boolean) => void;
|
|
11
11
|
isDesktop?: boolean;
|
|
12
|
+
closeHelpOnOutsideClick?: boolean;
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
export function QuestionHelp({
|
|
@@ -17,6 +18,7 @@ export function QuestionHelp({
|
|
|
17
18
|
children,
|
|
18
19
|
onChange = () => {},
|
|
19
20
|
isDesktop,
|
|
21
|
+
closeHelpOnOutsideClick = false,
|
|
20
22
|
}: QuestionHelpProps) {
|
|
21
23
|
const [isOpen, setIsOpen] = useState(false);
|
|
22
24
|
const ref = useRef<HTMLDivElement>(null);
|
|
@@ -32,12 +34,13 @@ export function QuestionHelp({
|
|
|
32
34
|
(event: MouseEvent) => {
|
|
33
35
|
if (
|
|
34
36
|
ref.current &&
|
|
35
|
-
!ref.current.contains(event.target as HTMLDivElement)
|
|
37
|
+
!ref.current.contains(event.target as HTMLDivElement) &&
|
|
38
|
+
closeHelpOnOutsideClick
|
|
36
39
|
) {
|
|
37
40
|
setIsOpen(false);
|
|
38
41
|
}
|
|
39
42
|
},
|
|
40
|
-
[setIsOpen],
|
|
43
|
+
[setIsOpen, closeHelpOnOutsideClick],
|
|
41
44
|
);
|
|
42
45
|
|
|
43
46
|
useEffect(() => {
|
|
@@ -55,6 +55,12 @@ import { Radio, RadioGroup } from "@simplybusiness/mobius";
|
|
|
55
55
|
|
|
56
56
|
### Normal
|
|
57
57
|
|
|
58
|
+
For a radio to appear selected use `value` prop which expects a string.
|
|
59
|
+
|
|
60
|
+
For example, `<RadioGroup defaultValue="blue">`
|
|
61
|
+
|
|
62
|
+
This will allow user to change the value. Alternatively, see _Controlled Value_ example.
|
|
63
|
+
|
|
58
64
|
<Canvas>
|
|
59
65
|
<Story
|
|
60
66
|
name="Normal"
|
|
@@ -64,6 +70,34 @@ import { Radio, RadioGroup } from "@simplybusiness/mobius";
|
|
|
64
70
|
errorMessage: "",
|
|
65
71
|
validationState: "",
|
|
66
72
|
orientation: "vertical",
|
|
73
|
+
defaultValue: "blue",
|
|
74
|
+
}}
|
|
75
|
+
>
|
|
76
|
+
{args => (
|
|
77
|
+
<RadioGroup {...args}>
|
|
78
|
+
<Radio value="red" label="Red" />
|
|
79
|
+
<Radio value="blue" label="Blue" />
|
|
80
|
+
</RadioGroup>
|
|
81
|
+
)}
|
|
82
|
+
</Story>
|
|
83
|
+
</Canvas>
|
|
84
|
+
|
|
85
|
+
### Controlled Value
|
|
86
|
+
|
|
87
|
+
You may want a radio to appear selected based on some conditional logic in another component.
|
|
88
|
+
|
|
89
|
+
You can use `value` prop which expects a string. To make `Blue` appear selected use `<RadioGroup value="blue">`
|
|
90
|
+
|
|
91
|
+
<Canvas>
|
|
92
|
+
<Story
|
|
93
|
+
name="Controlled Value"
|
|
94
|
+
args={{
|
|
95
|
+
label: "Color",
|
|
96
|
+
isDisabled: false,
|
|
97
|
+
errorMessage: "",
|
|
98
|
+
validationState: "",
|
|
99
|
+
orientation: "vertical",
|
|
100
|
+
value: "blue",
|
|
67
101
|
}}
|
|
68
102
|
>
|
|
69
103
|
{args => (
|
|
@@ -41,6 +41,12 @@ import { RadioButton, RadioGroup } from "@simplybusiness/mobius";
|
|
|
41
41
|
|
|
42
42
|
### Normal
|
|
43
43
|
|
|
44
|
+
For a radio button to appear selected use `value` prop which expects a string.
|
|
45
|
+
|
|
46
|
+
For example, `<RadioGroup defaultValue="blue">`
|
|
47
|
+
|
|
48
|
+
This will allow user to change the value. Alternatively, see _Controlled Value_ example.
|
|
49
|
+
|
|
44
50
|
<Canvas>
|
|
45
51
|
<Story
|
|
46
52
|
name="Normal"
|
|
@@ -48,6 +54,32 @@ import { RadioButton, RadioGroup } from "@simplybusiness/mobius";
|
|
|
48
54
|
label: "Color",
|
|
49
55
|
orientation: "horizontal",
|
|
50
56
|
isDisabled: false,
|
|
57
|
+
defaultValue: "blue",
|
|
58
|
+
}}
|
|
59
|
+
>
|
|
60
|
+
{args => (
|
|
61
|
+
<RadioGroup {...args}>
|
|
62
|
+
<RadioButton value="red">Red</RadioButton>
|
|
63
|
+
<RadioButton value="blue">Blue</RadioButton>
|
|
64
|
+
</RadioGroup>
|
|
65
|
+
)}
|
|
66
|
+
</Story>
|
|
67
|
+
</Canvas>
|
|
68
|
+
|
|
69
|
+
### Controlled Value
|
|
70
|
+
|
|
71
|
+
You may want a radio button to appear selected based on some conditional logic in another component.
|
|
72
|
+
|
|
73
|
+
You can use `value` prop which expects a string. To make `Blue` appear selected use `<RadioGroup value="blue">`
|
|
74
|
+
|
|
75
|
+
<Canvas>
|
|
76
|
+
<Story
|
|
77
|
+
name="Controlled Value"
|
|
78
|
+
args={{
|
|
79
|
+
label: "Color",
|
|
80
|
+
orientation: "horizontal",
|
|
81
|
+
isDisabled: false,
|
|
82
|
+
value: "blue",
|
|
51
83
|
}}
|
|
52
84
|
>
|
|
53
85
|
{args => (
|