mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 10:21:05 +00:00
feat(search): clear input on escape key (#448)
This commit is contained in:
parent
f6877f3809
commit
61753b8b82
4 changed files with 10 additions and 0 deletions
|
@ -2780,6 +2780,7 @@ None.
|
||||||
| input | forwarded | -- |
|
| input | forwarded | -- |
|
||||||
| focus | forwarded | -- |
|
| focus | forwarded | -- |
|
||||||
| blur | forwarded | -- |
|
| blur | forwarded | -- |
|
||||||
|
| keydown | forwarded | -- |
|
||||||
| clear | dispatched | -- |
|
| clear | dispatched | -- |
|
||||||
|
|
||||||
## `SearchSkeleton`
|
## `SearchSkeleton`
|
||||||
|
|
|
@ -2900,6 +2900,7 @@
|
||||||
{ "type": "forwarded", "name": "input", "element": "input" },
|
{ "type": "forwarded", "name": "input", "element": "input" },
|
||||||
{ "type": "forwarded", "name": "focus", "element": "input" },
|
{ "type": "forwarded", "name": "focus", "element": "input" },
|
||||||
{ "type": "forwarded", "name": "blur", "element": "input" },
|
{ "type": "forwarded", "name": "blur", "element": "input" },
|
||||||
|
{ "type": "forwarded", "name": "keydown", "element": "input" },
|
||||||
{ "type": "dispatched", "name": "clear" }
|
{ "type": "dispatched", "name": "clear" }
|
||||||
],
|
],
|
||||||
"typedefs": [],
|
"typedefs": [],
|
||||||
|
|
|
@ -120,6 +120,13 @@
|
||||||
}}"
|
}}"
|
||||||
on:focus
|
on:focus
|
||||||
on:blur
|
on:blur
|
||||||
|
on:keydown
|
||||||
|
on:keydown="{({ key }) => {
|
||||||
|
if (key === 'Escape') {
|
||||||
|
value = '';
|
||||||
|
dispatch('clear');
|
||||||
|
}
|
||||||
|
}}"
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
|
|
1
types/Search/Search.d.ts
vendored
1
types/Search/Search.d.ts
vendored
|
@ -97,6 +97,7 @@ export default class Search {
|
||||||
$on(eventname: "input", cb: (event: WindowEventMap["input"]) => void): () => void;
|
$on(eventname: "input", cb: (event: WindowEventMap["input"]) => void): () => void;
|
||||||
$on(eventname: "focus", cb: (event: WindowEventMap["focus"]) => void): () => void;
|
$on(eventname: "focus", cb: (event: WindowEventMap["focus"]) => void): () => void;
|
||||||
$on(eventname: "blur", cb: (event: WindowEventMap["blur"]) => void): () => void;
|
$on(eventname: "blur", cb: (event: WindowEventMap["blur"]) => void): () => void;
|
||||||
|
$on(eventname: "keydown", cb: (event: WindowEventMap["keydown"]) => void): () => void;
|
||||||
$on(eventname: "clear", cb: (event: CustomEvent<any>) => void): () => void;
|
$on(eventname: "clear", cb: (event: CustomEvent<any>) => void): () => void;
|
||||||
$on(eventname: string, cb: (event: Event) => void): () => void;
|
$on(eventname: string, cb: (event: Event) => void): () => void;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue