Skip to content

Commit

Permalink
fix(types): improve e.detail type for dispatched events (#1907)
Browse files Browse the repository at this point in the history
* fix(types): improve `e.detail` type for dispatched events

* Run "yarn build:docs"

* test: assert new types
  • Loading branch information
metonym authored Feb 1, 2024
1 parent f1cafd4 commit 6590457
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 35 deletions.
44 changes: 22 additions & 22 deletions COMPONENT_INDEX.md
Original file line number Diff line number Diff line change
Expand Up @@ -2151,9 +2151,9 @@ None.

### Events

| Event name | Type | Detail |
| :--------- | :--------- | :----- |
| clear | dispatched | -- |
| Event name | Type | Detail |
| :--------- | :--------- | :------------------------------------------- |
| clear | dispatched | <code>KeyboardEvent &#124; MouseEvent</code> |

## `ListItem`

Expand Down Expand Up @@ -3530,13 +3530,13 @@ None.

### Events

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

## `SliderSkeleton`

Expand Down Expand Up @@ -3578,13 +3578,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 | -- |

## `StructuredListBody`

Expand Down Expand Up @@ -3966,11 +3966,11 @@ None.

### Events

| Event name | Type | Detail |
| :--------- | :--------- | :----- |
| keypress | forwarded | -- |
| click | forwarded | -- |
| change | dispatched | -- |
| Event name | Type | Detail |
| :--------- | :--------- | :------------------ |
| change | dispatched | <code>number</code> |
| keypress | forwarded | -- |
| click | forwarded | -- |

## `TabsSkeleton`

Expand Down
20 changes: 13 additions & 7 deletions docs/src/COMPONENT_API.json
Original file line number Diff line number Diff line change
Expand Up @@ -6294,7 +6294,13 @@
],
"moduleExports": [],
"slots": [],
"events": [{ "type": "dispatched", "name": "clear" }],
"events": [
{
"type": "dispatched",
"name": "clear",
"detail": "KeyboardEvent | MouseEvent"
}
],
"typedefs": [
{
"type": "\"clearAll\" | \"clearSelection\"",
Expand Down Expand Up @@ -11354,11 +11360,11 @@
}
],
"events": [
{ "type": "dispatched", "name": "change", "detail": "number" },
{ "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 @@ -11446,11 +11452,11 @@
"moduleExports": [],
"slots": [{ "name": "__default__", "default": true, "slot_props": "{}" }],
"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 @@ -12245,9 +12251,9 @@
{ "name": "content", "default": false, "slot_props": "{}" }
],
"events": [
{ "type": "dispatched", "name": "change", "detail": "number" },
{ "type": "forwarded", "name": "keypress", "element": "div" },
{ "type": "forwarded", "name": "click", "element": "a" },
{ "type": "dispatched", "name": "change" }
{ "type": "forwarded", "name": "click", "element": "a" }
],
"typedefs": [],
"rest_props": { "type": "Element", "name": "div" }
Expand Down
4 changes: 4 additions & 0 deletions src/ListBox/ListBoxSelection.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<script>
/**
* @event {KeyboardEvent | MouseEvent} clear
*/
/**
* @typedef {"clearAll" | "clearSelection"} ListBoxSelectionTranslationId
*/
Expand Down
4 changes: 4 additions & 0 deletions src/Slider/Slider.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<script>
/**
* @event {number} change
*/
/** Specify the value of the slider */
export let value = 0;
Expand Down
4 changes: 4 additions & 0 deletions src/StructuredList/StructuredList.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<script>
/**
* @event {string} change
*/
/**
* Specify the selected structured list row value
* @type {string}
Expand Down
4 changes: 4 additions & 0 deletions src/Tabs/Tabs.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<script>
/**
* @event {number} change
*/
/** Specify the selected tab index */
export let selected = 0;
Expand Down
3 changes: 3 additions & 0 deletions tests/Slider.test.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
maxLabel="990 MB"
value="{100}"
fullWidth
on:change="{(e) => {
console.log(e.detail); // number
}}"
/>

<Slider
Expand Down
8 changes: 7 additions & 1 deletion tests/StructuredList.test.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@
import CheckmarkFilled from "carbon-icons-svelte/lib/CheckmarkFilled.svelte";
</script>

<StructuredList>
<StructuredList
selection
selected="row-1-value"
on:change="{(e) => {
console.log(e.detail); // string
}}"
>
<StructuredListHead>
<StructuredListRow head>
<StructuredListCell head>Column A</StructuredListCell>
Expand Down
6 changes: 5 additions & 1 deletion tests/Tabs.test.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
import { Tabs, Tab, TabContent, TabsSkeleton } from "../types";
</script>

<Tabs>
<Tabs
on:change="{(e) => {
console.log(e.detail); // number
}}"
>
<Tab label="Tab label 1" />
<Tab label="Tab label 2" />
<Tab label="Tab label 3" />
Expand Down
2 changes: 1 addition & 1 deletion types/ListBox/ListBoxSelection.svelte.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export interface ListBoxSelectionProps extends RestProps {

export default class ListBoxSelection extends SvelteComponentTyped<
ListBoxSelectionProps,
{ clear: CustomEvent<any> },
{ clear: CustomEvent<KeyboardEvent | MouseEvent> },
{}
> {
/**
Expand Down
2 changes: 1 addition & 1 deletion types/Slider/Slider.svelte.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ export interface SliderProps extends RestProps {
export default class Slider extends SvelteComponentTyped<
SliderProps,
{
change: CustomEvent<number>;
click: WindowEventMap["click"];
mouseover: WindowEventMap["mouseover"];
mouseenter: WindowEventMap["mouseenter"];
mouseleave: WindowEventMap["mouseleave"];
change: CustomEvent<any>;
},
{ labelText: {} }
> {}
2 changes: 1 addition & 1 deletion types/StructuredList/StructuredList.svelte.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ export interface StructuredListProps extends RestProps {
export default class StructuredList extends SvelteComponentTyped<
StructuredListProps,
{
change: CustomEvent<string>;
click: WindowEventMap["click"];
mouseover: WindowEventMap["mouseover"];
mouseenter: WindowEventMap["mouseenter"];
mouseleave: WindowEventMap["mouseleave"];
change: CustomEvent<any>;
},
{ default: {} }
> {}
2 changes: 1 addition & 1 deletion types/Tabs/Tabs.svelte.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ export interface TabsProps extends RestProps {
export default class Tabs extends SvelteComponentTyped<
TabsProps,
{
change: CustomEvent<number>;
keypress: WindowEventMap["keypress"];
click: WindowEventMap["click"];
change: CustomEvent<any>;
},
{ default: {}; content: {} }
> {}

0 comments on commit 6590457

Please sign in to comment.