Base Button

BaseButton is a building block to construct any clickable component with support for inbuilt a11y. It resets native styles provided to a button and takes care of keyboard modality.

When to use

  • To make any clickable component which doesn't follow already provided Button.
  • To make clickable areas or overlays on your components.
  • Need anchor functionality on custom component which isn't a button such as img with an href.

Accessibility

  • By default, BaseButton renders as a button.
  • BaseButton maintains accessibility upon overriding the component. No need of adding tabIndex or onKeyPress separately.
  • Add aria-label compulsorily for screen readers.

Examples

Clickable Media Card

Clickable Image with href

doggo

Play Card with Clickable Area

BaseButton props

NameTypeDefaultDescription
$as
string
Component to replace the default div container
aria-label
string
Sets aria-label attribute.
children
react node
Visible label.
className
string
Utility class names to be provided to BaseButton
onClick
function
Function called when base button is clicked.
style
string
styles to be provided to BaseButton

You can check the implementation of the component for more details.

BaseButton exports

You can import this module like so:

import {BaseButton} from 'spaceweb/base-button'

It exports the following components or utility functions:

  • BaseButton
  • StyledBaseButton
  • buttonResetStyles