Skip to content

Commit 06d81dd

Browse files
authored
fix(radio-button-group): strongly type dispatched change/select events (#1819)
1 parent 836b360 commit 06d81dd

8 files changed

+42
-18
lines changed

COMPONENT_INDEX.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -2983,13 +2983,13 @@ None.
29832983

29842984
### Events
29852985

2986-
| Event name | Type | Detail |
2987-
| :--------- | :--------- | :----- |
2988-
| click | forwarded | -- |
2989-
| mouseover | forwarded | -- |
2990-
| mouseenter | forwarded | -- |
2991-
| mouseleave | forwarded | -- |
2992-
| change | dispatched | -- |
2986+
| Event name | Type | Detail |
2987+
| :--------- | :--------- | :------------------ |
2988+
| change | dispatched | <code>string</code> |
2989+
| click | forwarded | -- |
2990+
| mouseover | forwarded | -- |
2991+
| mouseenter | forwarded | -- |
2992+
| mouseleave | forwarded | -- |
29932993

29942994
## `RadioButtonSkeleton`
29952995

@@ -4251,9 +4251,9 @@ export type CarbonTheme = "white" | "g10" | "g80" | "g90" | "g100";
42514251

42524252
### Events
42534253

4254-
| Event name | Type | Detail |
4255-
| :--------- | :--------- | :----- |
4256-
| select | dispatched | -- |
4254+
| Event name | Type | Detail |
4255+
| :--------- | :--------- | :------------------ |
4256+
| select | dispatched | <code>string</code> |
42574257

42584258
## `TimePicker`
42594259

docs/src/COMPONENT_API.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -9615,11 +9615,11 @@
96159615
}
96169616
],
96179617
"events": [
9618+
{ "type": "dispatched", "name": "change", "detail": "string" },
96189619
{ "type": "forwarded", "name": "click", "element": "div" },
96199620
{ "type": "forwarded", "name": "mouseover", "element": "div" },
96209621
{ "type": "forwarded", "name": "mouseenter", "element": "div" },
9621-
{ "type": "forwarded", "name": "mouseleave", "element": "div" },
9622-
{ "type": "dispatched", "name": "change" }
9622+
{ "type": "forwarded", "name": "mouseleave", "element": "div" }
96239623
],
96249624
"typedefs": [],
96259625
"rest_props": { "type": "Element", "name": "div" }
@@ -13158,7 +13158,9 @@
1315813158
],
1315913159
"moduleExports": [],
1316013160
"slots": [{ "name": "__default__", "default": true, "slot_props": "{}" }],
13161-
"events": [{ "type": "dispatched", "name": "select" }],
13161+
"events": [
13162+
{ "type": "dispatched", "name": "select", "detail": "string" }
13163+
],
1316213164
"typedefs": [],
1316313165
"rest_props": { "type": "Element", "name": "fieldset" }
1316413166
},

src/RadioButtonGroup/RadioButtonGroup.svelte

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
<script>
2+
/**
3+
* @event {string} change
4+
*/
5+
26
/**
37
* Set the selected radio button value
48
* @type {string}

src/Tile/TileGroup.svelte

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
<script>
2+
/**
3+
* @event {string} select
4+
*/
5+
26
/**
37
* Specify the selected tile value
48
* @type {string}

tests/RadioButton.test.svelte

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
import { RadioButton, RadioButtonSkeleton, RadioButtonGroup } from "../types";
33
</script>
44

5-
<RadioButtonGroup legendText="Storage tier (disk)" selected="standard">
5+
<RadioButtonGroup
6+
legendText="Storage tier (disk)"
7+
selected="standard"
8+
on:change="{(e) => {
9+
console.log(e.detail); // string
10+
}}"
11+
>
612
<RadioButton labelText="Free (1 GB)" value="free" />
713
<RadioButton labelText="Standard (10 GB)" value="standard" />
814
<RadioButton labelText="Pro (128 GB)" value="pro" />

tests/RadioTile.test.svelte

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@
22
import { TileGroup, RadioTile } from "../types";
33
</script>
44

5-
<TileGroup name="plan" required legend="Service pricing tiers">
6-
<RadioTile light value="0" checked>Lite plan</RadioTile>
5+
<TileGroup
6+
name="plan"
7+
required
8+
legend="Service pricing tiers"
9+
selected="0"
10+
on:select="{(e) => {
11+
console.log(e.detail); // string
12+
}}"
13+
>
14+
<RadioTile light checked value="0">Lite plan</RadioTile>
715
<RadioTile value="1">Standard plan</RadioTile>
816
<RadioTile value="2">Plus plan</RadioTile>
917
</TileGroup>

types/RadioButtonGroup/RadioButtonGroup.svelte.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ export interface RadioButtonGroupProps extends RestProps {
6464
export default class RadioButtonGroup extends SvelteComponentTyped<
6565
RadioButtonGroupProps,
6666
{
67+
change: CustomEvent<string>;
6768
click: WindowEventMap["click"];
6869
mouseover: WindowEventMap["mouseover"];
6970
mouseenter: WindowEventMap["mouseenter"];
7071
mouseleave: WindowEventMap["mouseleave"];
71-
change: CustomEvent<any>;
7272
},
7373
{ default: {}; legendText: {} }
7474
> {}

types/Tile/TileGroup.svelte.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ export interface TileGroupProps extends RestProps {
3939

4040
export default class TileGroup extends SvelteComponentTyped<
4141
TileGroupProps,
42-
{ select: CustomEvent<any> },
42+
{ select: CustomEvent<string> },
4343
{ default: {} }
4444
> {}

0 commit comments

Comments
 (0)