Button

241
<script>
  import { Button } from 'twelveui'
  function handleClick(event) {
    // do something
  }
</script>

<Button 
  on:click={handleClick} 
  class="m-8 px-7 py-4 rounded-lg bg-blue-600 text-white">
  Hello World!
</Button>

Accessibility

  • role='button' applied to <a> tag, when 'as' prop = 'a'
  • aria-pressed=false applied to <a> tag, when 'as' prop = 'a'
    • component handles the click event, to toggle aria-pressed value
  • aria-expanded=false applied to <a> tag, when 'as' prop = 'a'
    • component handles the click event, to toggle aria-expanded value
  • tabIndex='0' to enable keyboard navigation when 'as' prop = 'a'

Props

NameTypeDefaultDescription
asString'button'What html element to use when rendering the button.

[ 'button' | 'a' ]

Anything other than 'button' or 'a' will render a <button> element.
classStringemptyCSS class list.
disabledBooleanfalseIs the button disabled?

Only applies to <button> element.
expandedBooleanfalseThe aria-expanded attribute will be toggled when the button is clicked.

Only applies to <a> element.
expandedClassStringemptyCSS class to add to the button when expanded.

Only applies to <a> element, and expanded prop must also be passed.
hrefString'#'Only applies to <a> element.
idString'button'Element ID
nameString'button'Only applies to <button> element.
pressedBooleanfalseThe aria-pressed attribute will be toggled when the button is clicked.

Only applies to <a> element.
pressedClassStringemptyCSS class to add to the button when pressed.

Only applies to <a> element, and pressed prop must also be passed.
tabindexString'0'Only applies to <a> element.
targetString'_self'Where to load the URL.

Only applies to <a> element.
typeString'button'Only applies to <button> element.
valueStringemptyOnly applies to <button> element.

Events

on:click
on:dblclick
on:focus
on:keydown
on:mousedown
on:mouseover
on:submit