Options inside a `ChoiceList`. The wrapping `ChoiceList` component will dictate if the choice renders as radio buttons or checkboxes.
import {
reactExtension,
ChoiceList,
Choice,
BlockStack,
InlineStack,
} from '@shopify/ui-extensions-react/checkout';
export default reactExtension(
'purchase.checkout.block.render',
() => <Extension />,
);
function Extension() {
return (
<InlineStack>
<ChoiceList
name="choice"
value="first"
onChange={(value) => {
console.log(
`onChange event with value: ${value}`,
);
}}
>
<BlockStack>
<Choice id="first">Ship</Choice>
<Choice id="second">Pickup</Choice>
</BlockStack>
</ChoiceList>
<ChoiceList
name="choiceMultiple"
value={['multipleFirst']}
onChange={(value) => {
console.log(
`onChange event with value: ${value}`,
);
}}
>
<BlockStack>
<Choice id="multipleFirst">
Gift message
</Choice>
<Choice id="multipleSecond">
Gift wrapping
</Choice>
</BlockStack>
</ChoiceList>
</InlineStack>
);
}
import {
extension,
ChoiceList,
Choice,
BlockStack,
InlineStack,
} from '@shopify/ui-extensions/checkout';
export default extension('purchase.checkout.block.render', (root) => {
const choiceList = root.createComponent(
ChoiceList,
{
name: 'choice',
value: 'first',
onChange: (value) => {
console.log(`onChange event with value: ${value}`);
},
},
[
root.createComponent(BlockStack, undefined, [
root.createComponent(Choice, {id: 'first'}, 'Ship'),
root.createComponent(Choice, {id: 'second'}, 'Pickup'),
]),
],
);
const multipleChoiceList = root.createComponent(
ChoiceList,
{
name: 'multipleChoice',
value: ['multipleFirst'],
onChange: (value) => {
console.log(`onChange event with value: ${value}`);
},
},
[
root.createComponent(BlockStack, undefined, [
root.createComponent(Choice, {id: 'multipleFirst'}, 'Gift message'),
root.createComponent(Choice, {id: 'multipleSecond'}, 'Gift wrapping'),
]),
],
);
const layout = root.createComponent(InlineStack, undefined, [
choiceList,
multipleChoiceList,
]);
root.appendChild(layout);
});
A unique identifier for the choice.
Whether the choice can be changed.
A label used for buyers using assistive technologies. When set, any `children` supplied to this component will not be announced to screen reader users.