Skip to content

Commit 3fe782d

Browse files
committed
feat(radio-button): add helperText prop
1 parent 32e35e2 commit 3fe782d

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

src/RadioButtonGroup/RadioButtonGroup.svelte

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
/** Set to `true` to visually hide the legend */
3131
export let hideLegend = false;
3232
33+
/** Specify the helper text */
34+
export let helperText = "";
35+
3336
/**
3437
* Specify the label position
3538
* @type {"right" | "left"}
@@ -117,4 +120,12 @@
117120
{/if}
118121
<slot />
119122
</fieldset>
123+
{#if helperText}
124+
<div
125+
class:bx--form__helper-text={true}
126+
class:bx--form__helper-text--disabled={disabled}
127+
>
128+
{helperText}
129+
</div>
130+
{/if}
120131
</div>

tests/RadioButtonGroup/RadioButtonGroup.test.svelte

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
export let orientation: ComponentProps<RadioButtonGroup>["orientation"] =
1616
"horizontal";
1717
export let id: ComponentProps<RadioButtonGroup>["id"] = undefined;
18+
export let helperText: ComponentProps<RadioButtonGroup>["helperText"] = "";
1819
export let customClass = "";
1920
export let useSlot = false;
2021
</script>
@@ -29,6 +30,7 @@
2930
{labelPosition}
3031
{orientation}
3132
{id}
33+
{helperText}
3234
class={customClass}
3335
on:change={(e) => {
3436
console.log("change", e.detail);
@@ -50,6 +52,7 @@
5052
{labelPosition}
5153
{orientation}
5254
{id}
55+
{helperText}
5356
class={customClass}
5457
on:change={(e) => {
5558
console.log("change", e.detail);

tests/RadioButtonGroup/RadioButtonGroup.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,23 @@ describe("RadioButtonGroup", () => {
134134

135135
expect(component.selected).toBe("3");
136136
});
137+
138+
it("should render helper text when provided", () => {
139+
render(RadioButtonGroup, { props: { helperText: "Helper text message" } });
140+
const helperElement = screen
141+
.getByRole("group")
142+
.closest(".bx--form-item")
143+
?.querySelector(".bx--form__helper-text");
144+
assert(helperElement);
145+
expect(helperElement).toHaveTextContent("Helper text message");
146+
});
147+
148+
it("should not render helper text by default", () => {
149+
render(RadioButtonGroup);
150+
const helperElement = screen
151+
.getByRole("group")
152+
.closest(".bx--form-item")
153+
?.querySelector(".bx--form__helper-text");
154+
expect(helperElement).not.toBeInTheDocument();
155+
});
137156
});

types/RadioButtonGroup/RadioButtonGroup.svelte.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ type $Props = {
4040
*/
4141
hideLegend?: boolean;
4242

43+
/**
44+
* Specify the helper text
45+
* @default ""
46+
*/
47+
helperText?: string;
48+
4349
/**
4450
* Specify the label position
4551
* @default "right"

0 commit comments

Comments
 (0)