Skip to content

Commit 11bf0dd

Browse files
[Button]: Enable clicking via click via call (#1292)
1 parent 88dfec2 commit 11bf0dd

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/components/button/button.svelte

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,22 @@
5151
5252
export let onClick: (e: MouseEvent) => void = undefined
5353
54+
/**
55+
* Exposed so that the button can be clicked programmatically.
56+
*/
57+
export function click() {
58+
el?.click()
59+
}
60+
61+
let el: HTMLElement
62+
5463
$: tag = href ? 'a' : ('button' as 'a' | 'button')
5564
$: disabled = !!(isDisabled || (isDisabled as any) === '')
5665
</script>
5766

5867
<svelte:element
5968
this={tag}
69+
bind:this={el}
6070
href={href || undefined}
6171
class="leoButton"
6272
class:isFilled={kind === 'filled'}

0 commit comments

Comments
 (0)