v1.0.13

Select

Installation

Install yarn add @spark-web/select
Source GitHub.com
Bundle unpkg.com

Allows the user to make a single selection from a list of values — usually in a form. If only a few options are provided, consider using a RadioButton instead.

Usage

Field

Each select input must be accompanied by a Field with a label. Effective form labeling helps inform users which selection to make.

Examples

Controlled

A <Select> can be both controlled and uncontrolled. To control a <Select> provide a value, as well as an onChange function to set the new value when the select is updated.

Uncontrolled

The <Select>, by default, is an uncontrolled component, meaning that the form data is controlled directly by the DOM itself. To access the value, instead of writing an onChange handler, you would use a ref to get form values from the DOM.

Groups

Related options can be grouped by passing in an array of objects with a label and option key — where each option is an array of objects with label, value and (optionally) disabled keys. Internally this uses the <optgroup> element.

Props

PropTypeDescription

options

OptionsOrGroups

The values that can be selected by the input.

data?

DataAttributeMap

Sets data attributes for the element.

placeholder?

string

Placeholder text for when the input does not have an initial value.

© 2023 Brighte Capital Pty Ltd