docs(button): add "Programmatic focus" example

Related #1830
This commit is contained in:
metonym 2023-10-23 09:40:18 -07:00
commit 1114c4f024
2 changed files with 24 additions and 1 deletions

View file

@ -159,4 +159,12 @@ Set `expressive` to `true` to use Carbon's expressive typesetting.
<Button size="lg" skeleton />
<Button skeleton />
<Button skeleton size="field" />
<Button skeleton size="small" />
<Button skeleton size="small" />
## Programmatic focus
Bind to the `ref` prop to access a reference to the underlying button element.
You can use this reference to programmatically focus the button.
<FileSource src="/framed/Button/ProgrammaticFocus" />

View file

@ -0,0 +1,15 @@
<script>
import { Button } from "carbon-components-svelte";
let ref;
</script>
<Button bind:ref>Primary button</Button>
<Button
kind="ghost"
on:click="{() => {
ref?.focus();
}}"
>
Click to focus the Primary button
</Button>