Skip to content

Commit 78089fb

Browse files
committed
feat(checkbox): add helperText prop
1 parent 54d52e9 commit 78089fb

File tree

6 files changed

+60
-0
lines changed

6 files changed

+60
-0
lines changed

COMPONENT_INDEX.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ None.
468468
| disabled | No | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to disable the checkbox |
469469
| labelText | No | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the label text |
470470
| hideLabel | No | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to visually hide the label text |
471+
| helperText | No | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the helper text |
471472
| name | No | <code>let</code> | No | <code>string</code> | <code>""</code> | Set a name for the input element |
472473
| id | No | <code>let</code> | No | <code>string</code> | <code>"ccs-" + Math.random().toString(36)</code> | Set an id for the input label |
473474

@@ -2987,6 +2988,7 @@ None.
29872988
| name | No | <code>let</code> | No | <code>string</code> | <code>undefined</code> | Specify a name attribute for the radio button inputs |
29882989
| legendText | No | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the legend text |
29892990
| hideLegend | No | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to visually hide the legend |
2991+
| helperText | No | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the helper text |
29902992
| labelPosition | No | <code>let</code> | No | <code>"right" &#124; "left"</code> | <code>"right"</code> | Specify the label position |
29912993
| orientation | No | <code>let</code> | No | <code>"horizontal" &#124; "vertical"</code> | <code>"horizontal"</code> | Specify the orientation of the radio buttons |
29922994
| id | No | <code>let</code> | No | <code>string</code> | <code>undefined</code> | Set an id for the container div element |

docs/src/COMPONENT_API.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,18 @@
10311031
"constant": false,
10321032
"reactive": false
10331033
},
1034+
{
1035+
"name": "helperText",
1036+
"kind": "let",
1037+
"description": "Specify the helper text",
1038+
"type": "string",
1039+
"value": "\"\"",
1040+
"isFunction": false,
1041+
"isFunctionDeclaration": false,
1042+
"isRequired": false,
1043+
"constant": false,
1044+
"reactive": false
1045+
},
10341046
{
10351047
"name": "name",
10361048
"kind": "let",
@@ -11530,6 +11542,18 @@
1153011542
"constant": false,
1153111543
"reactive": false
1153211544
},
11545+
{
11546+
"name": "helperText",
11547+
"kind": "let",
11548+
"description": "Specify the helper text",
11549+
"type": "string",
11550+
"value": "\"\"",
11551+
"isFunction": false,
11552+
"isFunctionDeclaration": false,
11553+
"isRequired": false,
11554+
"constant": false,
11555+
"reactive": false
11556+
},
1153311557
{
1153411558
"name": "labelPosition",
1153511559
"kind": "let",

src/Checkbox/Checkbox.svelte

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
/** Set to `true` to visually hide the label text */
4141
export let hideLabel = false;
4242
43+
/** Specify the helper text */
44+
export let helperText = "";
45+
4346
/** Set a name for the input element */
4447
export let name = "";
4548
@@ -136,5 +139,13 @@
136139
</slot>
137140
</span>
138141
</label>
142+
{#if helperText}
143+
<div
144+
class:bx--form__helper-text={true}
145+
class:bx--form__helper-text--disabled={disabled}
146+
>
147+
{helperText}
148+
</div>
149+
{/if}
139150
</div>
140151
{/if}

tests/Checkbox/Checkbox.test.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
export let disabled = false;
77
export let hideLabel = false;
88
export let labelText = "Checkbox label";
9+
export let helperText = "";
910
</script>
1011

1112
<Checkbox
@@ -14,6 +15,7 @@
1415
{disabled}
1516
{hideLabel}
1617
{labelText}
18+
{helperText}
1719
data-testid="checkbox"
1820
on:check={() => console.log("check")}
1921
on:click={() => console.log("click")}

tests/Checkbox/Checkbox.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,4 +440,19 @@ describe("Checkbox", () => {
440440
await user.click(input);
441441
expect(input).toBeChecked();
442442
});
443+
444+
it("should render helper text when provided", () => {
445+
render(Checkbox, { helperText: "Helper text message" });
446+
const wrapper = screen.getByTestId("checkbox");
447+
const helperElement = wrapper.querySelector(".bx--form__helper-text");
448+
assert(helperElement);
449+
expect(helperElement).toHaveTextContent("Helper text message");
450+
});
451+
452+
it("should not render helper text by default", () => {
453+
render(Checkbox);
454+
const wrapper = screen.getByTestId("checkbox");
455+
const helperElement = wrapper.querySelector(".bx--form__helper-text");
456+
expect(helperElement).not.toBeInTheDocument();
457+
});
443458
});

types/Checkbox/Checkbox.svelte.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ type $Props = {
6464
*/
6565
hideLabel?: boolean;
6666

67+
/**
68+
* Specify the helper text
69+
* @default ""
70+
*/
71+
helperText?: string;
72+
6773
/**
6874
* Set a name for the input element
6975
* @default ""

0 commit comments

Comments
 (0)