Next to the properties listed in the propstable, a collection of system props can be added to any component for further general styling and layouting purposes. These props vary per component.
Marking a Select as disabled, will disable all interaction with the element.
()=>{
const options =['Nope','not','possible'];
const[value, setValue]= React.useState('');
return(
<Select
id="disabled"
value={value}
onChange={e=>setValue(e.target.value)}
label="Label"
disabled
>
{options.map(option=>(
<optionkey={option}value={option}>
{option}
</option>
))}
</Select>
);
};
Error
default: undefined
To convey an error to the user, you can set the error prop to true.
()=>{
const options =['Whoops',"Thath's",'a','fail'];
const[value, setValue]= React.useState('');
return(
<Select
id="error"
value={value}
onChange={e=>setValue(e.target.value)}
label="Label"
error
>
{options.map(option=>(
<optionkey={option}value={option}>
{option}
</option>
))}
</Select>
);
};
IconLeft
default: undefined
For further illustration purposes, you can provide an iconLeft.
()=>{
const options =['Hot','And','Trending'];
const[value, setValue]= React.useState('');
return(
<Select
id="iconLeft"
value={value}
onChange={e=>setValue(e.target.value)}
label="Label"
iconLeft={TrendingFill}
>
{options.map(option=>(
<optionkey={option}value={option}>
{option}
</option>
))}
</Select>
);
};
LabelHidden
default: undefined
To meet accessibility requirements, every Select should have an associated
label. We do support the ability to visually hide the label when the Select's
purpose is clear.
()=>{
const options =['Always','Add','Label'];
const[value, setValue]= React.useState('');
return(
<Select
id="labelHidden"
value={value}
onChange={e=>setValue(e.target.value)}
label="Label"
labelHidden
>
{options.map(option=>(
<optionkey={option}value={option}>
{option}
</option>
))}
</Select>
);
};
Message
default: undefined
Give additional information to the user.
Message can be set to provide additional information.
()=>{
const options =['A','bit','more','context'];
const[value, setValue]= React.useState('');
return(
<Select
id="message"
value={value}
onChange={e=>setValue(e.target.value)}
label="Label"
message="Message can be set to provide additional information."
>
{options.map(option=>(
<optionkey={option}value={option}>
{option}
</option>
))}
</Select>
);
};
OptionalLabel (Required fields)
default: undefined
By default the Select is always required. To make a Slect optional you can
add the optionalLabel prop.
With Chameleon we take a specific approach where we encourage marking optional
fields, not required. The majority of fields in a form are always required.
Indicating that fields are required make users more fearful, it increases the
risk of errors and reduces the form completion rate.
()=>{
const options =['Not','so','required'];
const[value, setValue]= React.useState('');
return(
<Select
id="optionalLabel"
value={value}
onChange={e=>setValue(e.target.value)}
label="Label"
optionalLabel="I'm optional"
>
{options.map(option=>(
<optionkey={option}value={option}>
{option}
</option>
))}
</Select>
);
};
Placeholder
default: undefined
Placeholder text is displayed inside the field but is not always necessary. They
should be written as examples helping users to understand the required input
instead of instructions.
()=>{
const options =['Nope','not','a','default'];
const[value, setValue]= React.useState('');
return(
<Select
id="placeholder"
value={value}
placeholder="Make a selection..."
onChange={e=>setValue(e.target.value)}
label="Label"
>
{options.map(option=>(
<optionkey={option}value={option}>
{option}
</option>
))}
</Select>
);
};
Required
default: true
By default the Select is required. You can change this by providing a
optionalLabel or passing false to the required prop. We encourage you to use the
optionalLabel prop, this provides additional feedback to the user!