mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-20 12:23:02 +00:00
docs(combo-box): add clear without focus to "Clear selection" example
This commit is contained in:
parent
f113395024
commit
ab4a0fa129
2 changed files with 25 additions and 12 deletions
|
@ -1,9 +1,6 @@
|
||||||
<script>
|
<script>
|
||||||
import { ComboBox } from "carbon-components-svelte";
|
import { ComboBox } from "carbon-components-svelte";
|
||||||
import { Button } from "carbon-components-svelte";
|
|
||||||
import Preview from "../../components/Preview.svelte";
|
import Preview from "../../components/Preview.svelte";
|
||||||
let comboboxComponent
|
|
||||||
let selectedIndex = 1
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
### Default
|
### Default
|
||||||
|
@ -31,15 +28,11 @@ items={[
|
||||||
|
|
||||||
### Clear selection
|
### Clear selection
|
||||||
|
|
||||||
<ComboBox titleText="Contact" placeholder="Select contact method"
|
To programmatically clear the selection, access the component instance using the [bind:this](https://svelte.dev/docs#bind_element) directive and invoke the `ComboBox.clear()` accessor.
|
||||||
bind:this={comboboxComponent}
|
|
||||||
items={[
|
Specify `focus: false` in the method options to avoid re-focusing the input.
|
||||||
{id: "0", text: "Slack"},
|
|
||||||
{id: "1", text: "Email"},
|
<FileSource src="/framed/ComboBox/ComboBoxClear" />
|
||||||
{id: "2", text: "Fax"}
|
|
||||||
]} />
|
|
||||||
<br>
|
|
||||||
<Button on:click={comboboxComponent.clear}>Clear</Button>
|
|
||||||
|
|
||||||
### Multiple combo boxes
|
### Multiple combo boxes
|
||||||
|
|
||||||
|
|
20
docs/src/pages/framed/ComboBox/ComboBoxClear.svelte
Normal file
20
docs/src/pages/framed/ComboBox/ComboBoxClear.svelte
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
<script>
|
||||||
|
import { ComboBox, Button } from "carbon-components-svelte";
|
||||||
|
|
||||||
|
let ref;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<ComboBox
|
||||||
|
titleText="Contact"
|
||||||
|
placeholder="Select contact method"
|
||||||
|
selectedIndex="{1}"
|
||||||
|
bind:this="{ref}"
|
||||||
|
items="{[
|
||||||
|
{ id: '0', text: 'Slack' },
|
||||||
|
{ id: '1', text: 'Email' },
|
||||||
|
{ id: '2', text: 'Fax' },
|
||||||
|
]}"
|
||||||
|
/>
|
||||||
|
<br />
|
||||||
|
<Button on:click="{ref.clear}">Clear</Button>
|
||||||
|
<Button on:click="{() => ref.clear({ focus: false })}">Clear (no focus)</Button>
|
Loading…
Add table
Add a link
Reference in a new issue