Skip to content

Commit eb8a543

Browse files
committed
Add disable support for RadioButtonGroupInput choices
1 parent a99880b commit eb8a543

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-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
@@ -388,4 +399,4 @@ const CompanyInput = () => (
388399

389400
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.
390401

391-
**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).
402+
**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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,13 @@ export const TranslateChoice = () => {
272272
</AdminContext>
273273
);
274274
};
275+
276+
export const DisabledChoice = () => (
277+
<Wrapper>
278+
<RadioButtonGroupInput source="category" choices={[
279+
{ id: 'tech', name: 'Tech', details: 'Tech details' },
280+
{ id: 'lifestyle', name: 'Lifestyle', details: 'Lifestyle details' },
281+
{ id: 'people', name: 'People', details: 'People details', disabled: true },
282+
]} />
283+
</Wrapper>
284+
);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ export const RadioButtonGroupInputItem = ({
1010
source,
1111
translateChoice,
1212
}) => {
13-
const { getChoiceText, getChoiceValue } = useChoices({
13+
const { getChoiceText, getChoiceValue, getDisableValue } = useChoices({
1414
optionText,
1515
optionValue,
1616
translateChoice,
1717
});
1818
const label = getChoiceText(choice);
1919
const value = getChoiceValue(choice);
20+
const disabled = getDisableValue(choice);
2021

2122
const nodeId = `${source}_${value}`;
2223

@@ -25,6 +26,7 @@ export const RadioButtonGroupInputItem = ({
2526
label={label}
2627
htmlFor={nodeId}
2728
value={value}
29+
disabled={disabled}
2830
control={<Radio id={nodeId} color="primary" />}
2931
/>
3032
);

0 commit comments

Comments
 (0)