Skip to content

Commit

Permalink
docs(button): add "Programmatic focus" example
Browse files Browse the repository at this point in the history
Related #1830
  • Loading branch information
metonym committed Oct 23, 2023
1 parent 6855633 commit 1114c4f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
10 changes: 9 additions & 1 deletion docs/src/pages/components/Button.svx
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
15 changes: 15 additions & 0 deletions docs/src/pages/framed/Button/ProgrammaticFocus.svelte
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit 1114c4f

Please sign in to comment.