Skip to content

Commit 6abea44

Browse files
author
Sine Jespersen
committed
5391: validation on checkbox
1 parent 5f04223 commit 6abea44

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

src/stories/Library/Forms/checkbox/Checkbox.stories.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ export default {
1212
type: "text",
1313
},
1414
},
15+
validation: {
16+
control: {
17+
type: "text",
18+
defaultValue: "",
19+
},
20+
},
1521
// We disable the isChecked control, since it is not possible to
1622
// get the states from the React component to work with Storybook controls.
1723
isChecked: {
@@ -37,6 +43,7 @@ export const Unchecked = Template.bind({});
3743
Unchecked.args = {
3844
isChecked: false,
3945
label: "Toggle this checkbox",
46+
validation: "Error error error",
4047
};
4148

4249
// Show multiple checkboxes to make it easier to test keyboard navigation.

src/stories/Library/Forms/checkbox/Checkbox.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export type CheckboxProps = {
44
isChecked: boolean;
55
label?: string;
66
ariaLabel?: string;
7+
validation?: string;
78
callback?: (isChecked: boolean) => void;
89
};
910

@@ -12,6 +13,7 @@ export const Checkbox: React.FC<CheckboxProps> = ({
1213
label,
1314
ariaLabel,
1415
callback,
16+
validation,
1517
}) => {
1618
const checkboxId = useRef(`checkbox_id__${Math.random()}`);
1719
const [checked, setChecked] = useState(isChecked);
@@ -46,11 +48,18 @@ export const Checkbox: React.FC<CheckboxProps> = ({
4648
/>
4749
</svg>
4850
</span>
49-
{label && (
50-
<span className="checkbox__text text-small-caption color-secondary-gray">
51-
{label}
52-
</span>
53-
)}
51+
<div>
52+
{label && (
53+
<span className="checkbox__text text-small-caption color-secondary-gray">
54+
{label}
55+
</span>
56+
)}
57+
{validation && (
58+
<div className="checkbox__text text-small-caption checkbox__text--validation">
59+
{validation}
60+
</div>
61+
)}
62+
</div>
5463
</label>
5564
</div>
5665
);

src/stories/Library/Forms/checkbox/checkbox.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,13 @@
4545
transform: translate3d(0, 0, 0);
4646
}
4747

48-
.checkbox__label .checkbox__text:last-child {
48+
.checkbox__label .checkbox__text {
4949
padding-left: 8px;
5050
line-height: 18px;
51+
52+
&--validation {
53+
color: $c-signal-alert;
54+
}
5155
}
5256

5357
.checkbox__label:hover .checkbox__icon:first-child {

0 commit comments

Comments
 (0)