Skip to content

Commit

Permalink
fix(radio): strongly type dispatched change/select events
Browse files Browse the repository at this point in the history
  • Loading branch information
metonym committed Oct 3, 2023
1 parent 5ef4dc1 commit f68fb08
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 17 deletions.
20 changes: 10 additions & 10 deletions COMPONENT_INDEX.md
Original file line number Diff line number Diff line change
Expand Up @@ -2983,13 +2983,13 @@ None.

### Events

| Event name | Type | Detail |
| :--------- | :--------- | :----- |
| click | forwarded | -- |
| mouseover | forwarded | -- |
| mouseenter | forwarded | -- |
| mouseleave | forwarded | -- |
| change | dispatched | -- |
| Event name | Type | Detail |
| :--------- | :--------- | :------------------ |
| change | dispatched | <code>string</code> |
| click | forwarded | -- |
| mouseover | forwarded | -- |
| mouseenter | forwarded | -- |
| mouseleave | forwarded | -- |

## `RadioButtonSkeleton`

Expand Down Expand Up @@ -4248,9 +4248,9 @@ export type CarbonTheme = "white" | "g10" | "g80" | "g90" | "g100";

### Events

| Event name | Type | Detail |
| :--------- | :--------- | :----- |
| select | dispatched | -- |
| Event name | Type | Detail |
| :--------- | :--------- | :------------------ |
| select | dispatched | <code>string</code> |

## `TimePicker`

Expand Down
8 changes: 5 additions & 3 deletions docs/src/COMPONENT_API.json
Original file line number Diff line number Diff line change
Expand Up @@ -9615,11 +9615,11 @@
}
],
"events": [
{ "type": "dispatched", "name": "change", "detail": "string" },
{ "type": "forwarded", "name": "click", "element": "div" },
{ "type": "forwarded", "name": "mouseover", "element": "div" },
{ "type": "forwarded", "name": "mouseenter", "element": "div" },
{ "type": "forwarded", "name": "mouseleave", "element": "div" },
{ "type": "dispatched", "name": "change" }
{ "type": "forwarded", "name": "mouseleave", "element": "div" }
],
"typedefs": [],
"rest_props": { "type": "Element", "name": "div" }
Expand Down Expand Up @@ -13125,7 +13125,9 @@
],
"moduleExports": [],
"slots": [{ "name": "__default__", "default": true, "slot_props": "{}" }],
"events": [{ "type": "dispatched", "name": "select" }],
"events": [
{ "type": "dispatched", "name": "select", "detail": "string" }
],
"typedefs": [],
"rest_props": { "type": "Element", "name": "fieldset" }
},
Expand Down
4 changes: 4 additions & 0 deletions src/RadioButtonGroup/RadioButtonGroup.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<script>
/**
* @event {string} change
*/
/**
* Set the selected radio button value
* @type {string}
Expand Down
4 changes: 4 additions & 0 deletions src/Tile/TileGroup.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<script>
/**
* @event {string} select
*/
/**
* Specify the selected tile value
* @type {string}
Expand Down
8 changes: 7 additions & 1 deletion tests/RadioButton.test.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
import { RadioButton, RadioButtonSkeleton, RadioButtonGroup } from "../types";
</script>

<RadioButtonGroup legendText="Storage tier (disk)" selected="standard">
<RadioButtonGroup
legendText="Storage tier (disk)"
selected="standard"
on:change="{(e) => {
console.log(e.detail); // string
}}"
>
<RadioButton labelText="Free (1 GB)" value="free" />
<RadioButton labelText="Standard (10 GB)" value="standard" />
<RadioButton labelText="Pro (128 GB)" value="pro" />
Expand Down
7 changes: 6 additions & 1 deletion tests/RadioTile.test.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
import { TileGroup, RadioTile } from "../types";
</script>

<TileGroup legend="Service pricing tiers">
<TileGroup
legend="Service pricing tiers"
on:select="{(e) => {
console.log(e.detail); // string
}}"
>
<RadioTile value="0" checked>Lite plan</RadioTile>
<RadioTile value="1">Standard plan</RadioTile>
<RadioTile value="2">Plus plan</RadioTile>
Expand Down
2 changes: 1 addition & 1 deletion types/RadioButtonGroup/RadioButtonGroup.svelte.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ export interface RadioButtonGroupProps extends RestProps {
export default class RadioButtonGroup extends SvelteComponentTyped<
RadioButtonGroupProps,
{
change: CustomEvent<string>;
click: WindowEventMap["click"];
mouseover: WindowEventMap["mouseover"];
mouseenter: WindowEventMap["mouseenter"];
mouseleave: WindowEventMap["mouseleave"];
change: CustomEvent<any>;
},
{ default: {}; legendText: {} }
> {}
2 changes: 1 addition & 1 deletion types/Tile/TileGroup.svelte.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ export interface TileGroupProps extends RestProps {

export default class TileGroup extends SvelteComponentTyped<
TileGroupProps,
{ select: CustomEvent<any> },
{ select: CustomEvent<string> },
{ default: {} }
> {}

0 comments on commit f68fb08

Please sign in to comment.