UNPKG

@shopify/polaris

Version:

Shopify’s product component library

173 lines (118 loc) 3.67 kB
--- name: Radio button category: Forms platforms: - android - ios - web keywords: - RadioButton - selection - choices - options - pick - single selection form - choice form - option button - radio button form - toggle - switch --- # Radio button Use radio buttons to present each item in a list of options where merchants must make a single selection. --- ## Best practices Radio buttons should: - Always be used with an associated label component. - Be part of a list of radio buttons that: - Include at least two or more choices. - Are used to have merchants select only one option. - Include mutually exclusive options—this means that each option must be independent from every other option in the list. For example: Red, blue, and yellow are mutually exclusive. Red, blue, yellow, red/blue are not mutually exclusive. - List options in a rational order that makes logical sense. --- ## Content guidelines ### Radio button labels Radio button labels should: - Be introduced with a colon or a heading - Start with a capital letter <!-- usagelist --> #### Do - Option 1 #### Don’t - option 1 <!-- end --> - Not end in punctuation if it’s a single sentence, word, or a fragment <!-- usagelist --> #### Do - Red #### Don’t - Red; <!-- end --> ### Toggle (Android and iOS only) Toggle labels should: - Be clear what merchants are enabling or disabling - Start with a capital letter Toggle values should: - Never be labeled --- ## Examples ### Default radio button Use radio buttons where merchants must make a single selection. ```jsx class RadioButtonExample extends React.Component { state = { value: 'disabled', }; handleChange = (checked, newValue) => { this.setState({value: newValue}); }; render() { const {value} = this.state; return ( <Stack vertical> <RadioButton label="Accounts are disabled" helpText="Customers will only be able to check out as guests." checked={value === 'disabled'} id="disabled" name="accounts" onChange={this.handleChange} /> <RadioButton label="Accounts are optional" helpText="Customers will be able to check out with a customer account or as a guest." id="optional" name="accounts" checked={value === 'optional'} onChange={this.handleChange} /> </Stack> ); } } ``` <!-- content-for: android --> ![Default radio button on Android](components/RadioButton/android/default.png) <!-- /content-for --> <!-- content-for: ios --> ![Default radio button on iOS](components/RadioButton/ios/default.png) <!-- /content-for --> ### Toggle <!-- example-for: android, ios --> Use toggles when merchants need to make a binary choice (on or off). <!-- content-for: android --> ![Android toggle with on or off options](components/RadioButton/android/toggle.png) <!-- /content-for --> <!-- content-for: ios --> ![iOS toggle with on or off options](components/RadioButton/ios/toggle.png) <!-- /content-for --> --- ## Related components - To make simple lists of radio buttons easier to build, [use the choice list component](/components/forms/choice-list) - For long lists of options, [consider the select component](/components/forms/select) to avoid overwhelming merchants - To present merchants with a list of checkboxes, [use the choice list component](/components/forms/choice-list) with the “allow multiple” option - To display non-interactive list of related content, [use the content list component](/components/lists-and-tables/list)