The Select component is used for collecting user provided information from a list of options.
Import
import{
Select,
Option,
OptionGroup,
}from'@trendmicro/react-styled-ui';
Usage
EDITABLE EXAMPLE
<>
<TextLabelmb="1x">Label:</TextLabel>
<Select>
<Optionvalue="">Choose an option</Option>
<OptionGrouplabel="Category 1">
<Optionvalue={1}>Option 1</Option>
<Optionvalue={2}>Option 2</Option>
</OptionGroup>
<OptionGrouplabel="Category 2">
<Optionvalue={3}>Option 3</Option>
<Optionvalue={4}>Option 4</Option>
</OptionGroup>
</Select>
</>
Variants
The Select component comes in 3 variants: outline, filled, and unstyled. Pass the variant prop and set it to either of these values.
outline
EDITABLE EXAMPLE
<Selectvariant="outline">
<Optionvalue="">Choose an option</Option>
<Optionvalue="outline">Outline</Option>
</Select>
filled
EDITABLE EXAMPLE
<Selectvariant="filled">
<Optionvalue="">Choose an option</Option>
<Optionvalue="filled">Filled</Option>
</Select>
unstyled
EDITABLE EXAMPLE
<Selectvariant="unstyled">
<Optionvalue="">Choose an option</Option>
<Optionvalue="unstyled">Unstyled</Option>
</Select>
Attributes
The <select> element has some unique attributes you can use to control it, such as multiple to specify whether multiple options can be selected, and size to specify how many options should be shown at once. It also accepts most of the general form input attributes such as disabled, required, etc.
Multiple options
EDITABLE EXAMPLE
constFlexOption=({ style,...props })=>(
<Flex
as="option"
align="center"
height="8x"
px="3x"
{...props}
/>
);
functionExample(){
return(
<Selectmultiplesize="4">
<FlexOptionvalue={1}>Option 1</FlexOption>
<FlexOptionvalue={2}>Option 2</FlexOption>
<FlexOptionvalue={3}>Option 3</FlexOption>
<FlexOptionvalue={4}>Option 4</FlexOption>
<FlexOptionvalue={5}>Option 5</FlexOption>
<FlexOptionvalue={6}>Option 6</FlexOption>
</Select>
);
}
render(<Example/>);
disabled
EDITABLE EXAMPLE
<Selectdisabled>
<Optionvalue="">Choose an option</Option>
</Select>
required
EDITABLE EXAMPLE
<Selectrequired>
<Optionvalue="">Choose an option</Option>
<Optionvalue="dog">Dog</Option>
<Optionvalue="cat">Cat</Option>
</Select>
Props
Select
Name
Type
Default
Description
variant
string
'outline'
The variant of the select style to use. One of: 'outline', 'filled', 'unstyled'
disabled
boolean
If true, the user cannot interact with the control. This sets aria-disabled=true and you can style this state by passing the _disabled prop.
isInvalid
boolean
If true, the input will indicate an error. You can style this state by passing the _invalid prop.