Skip to content

Commit 998bb1b

Browse files
committed
Add disable support for RadioButtonGroupInput choices
1 parent b66f0ac commit 998bb1b

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

docs/RadioButtonGroupInput.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@ const choices = [
9494
/>
9595
```
9696

97+
You can render some options as disabled by setting the `disabled` field in some choices:
98+
99+
```jsx
100+
const choices = [
101+
{ id: 'tech', name: 'Tech' },
102+
{ id: 'lifestyle', name: 'Lifestyle' },
103+
{ id: 'people', name: 'People', disabled: true },
104+
];
105+
<RadioButtonGroupInput source="category" choices={choices} />
106+
```
107+
97108
The choices are translated by default, so you can use translation identifiers as choices:
98109

99110
```jsx
@@ -390,4 +401,4 @@ const CompanyInput = () => (
390401

391402
This is the recommended approach for using `<RadioButtonGroupInput>` to select a foreign key. This not only signifies that the input is a `<RadioButtonGroupInput>` but also highlights its function in fetching choices from another resource, ultimately enhancing the code's readability.
392403

393-
**Tip**: `<ReferenceInput>` is much more powerful than the initial snippet. It optimizes and caches API calls, enables refetching of both API calls with a single command, and stores supplementary data in the `<ChoicesContext>`. `<ReferenceInput>` can provide choices to `<RadioButtonGroupInput>`, but also to [`<AutocompleteInput>`](./AutocompleteInput.md) and [`<SelectInput>`](./SelectInput.md). For further information, refer to [the `<ReferenceInput>` documentation](./ReferenceInput.md).
404+
**Tip**: `<ReferenceInput>` is much more powerful than the initial snippet. It optimizes and caches API calls, enables refetching of both API calls with a single command, and stores supplementary data in the `<ChoicesContext>`. `<ReferenceInput>` can provide choices to `<RadioButtonGroupInput>`, but also to [`<AutocompleteInput>`](./AutocompleteInput.md) and [`<SelectInput>`](./SelectInput.md). For further information, refer to [the `<ReferenceInput>` documentation](./ReferenceInput.md).

packages/ra-ui-materialui/src/input/RadioButtonGroupInput.stories.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,28 @@ export const TranslateChoice = () => {
278278
);
279279
};
280280

281+
export const DisabledChoice = () => (
282+
<Wrapper>
283+
<RadioButtonGroupInput
284+
source="category"
285+
choices={[
286+
{ id: 'tech', name: 'Tech', details: 'Tech details' },
287+
{
288+
id: 'lifestyle',
289+
name: 'Lifestyle',
290+
details: 'Lifestyle details',
291+
},
292+
{
293+
id: 'people',
294+
name: 'People',
295+
details: 'People details',
296+
disabled: true,
297+
},
298+
]}
299+
/>
300+
</Wrapper>
301+
);
302+
281303
export const Themed = () => (
282304
<Wrapper
283305
theme={createTheme({

packages/ra-ui-materialui/src/input/RadioButtonGroupInputItem.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ export const RadioButtonGroupInputItem = (
2525
name: PREFIX,
2626
});
2727

28-
const { getChoiceText, getChoiceValue } = useChoices({
28+
const { getChoiceText, getChoiceValue, getDisableValue } = useChoices({
2929
optionText,
3030
optionValue,
3131
translateChoice,
3232
});
3333
const label = getChoiceText(choice);
3434
const value = getChoiceValue(choice);
35+
const disabled = getDisableValue(choice);
3536

3637
const nodeId = `${source}_${value}`;
3738

@@ -40,6 +41,7 @@ export const RadioButtonGroupInputItem = (
4041
label={label}
4142
htmlFor={nodeId}
4243
value={value}
44+
disabled={disabled}
4345
control={<Radio id={nodeId} color="primary" />}
4446
{...sanitizeInputRestProps(rest)}
4547
/>

0 commit comments

Comments
 (0)