Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RadioItem: Add disabled support #1108

Merged
merged 2 commits into from
May 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .changeset/forty-coins-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
'braid-design-system': minor
---

---
updated:
- RadioItem
---

**RadioItem:** Add `disabled` support

Provide support for disabling individual `RadioItem`s within a `RadioGroup`.

**EXAMPLE USAGE:**
```jsx
<RadioGroup>
<RadioItem label="One" value="1" />
<RadioItem label="Two" value="2" />
<RadioItem label="Three" value="3" disabled={true} />
</RadioGroup>
```
Original file line number Diff line number Diff line change
Expand Up @@ -6673,6 +6673,7 @@ Object {
children?: ReactNode
data?: DataAttributeMap
description?: ReactNode
disabled?: boolean
label: ReactNode
ref?:
| (instance: HTMLInputElement | null) => void
Expand Down
28 changes: 26 additions & 2 deletions lib/components/RadioGroup/RadioGroup.docs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ const docs: ComponentDocs = {
label: 'Disabled field',
description: (
<Text>
Mark the field as disabled by passing <Strong>true</Strong> to the{' '}
<Strong>disabled</Strong> prop.
Mark the entire <Strong>RadioGroup</Strong> as disabled by passing{' '}
<Strong>true</Strong> to the <Strong>disabled</Strong> prop.
</Text>
),
Example: ({ id }) =>
Expand All @@ -176,6 +176,30 @@ const docs: ComponentDocs = {
</RadioGroup>,
),
},
{
label: 'Disabling at item-level',
description: (
<Text>
Mark an individual <Strong>RadioItem</Strong> as disabled by passing{' '}
<Strong>true</Strong> to its <Strong>disabled</Strong> prop.
</Text>
),
Example: ({ id, getState, setState }) =>
source(
<RadioGroup
id={id}
value={getState('radio')}
onChange={({ currentTarget: { value } }) =>
setState('radio', value)
}
label="Label"
>
<RadioItem label="One" value="1" />
<RadioItem label="Two" value="2" />
<RadioItem label="Three" value="3" disabled={true} />
</RadioGroup>,
),
},
{
label: 'Item-level descriptions',
description: (
Expand Down
16 changes: 16 additions & 0 deletions lib/components/RadioGroup/RadioGroup.screenshots.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,21 @@ export const screenshots: ComponentScreenshot = {
);
},
},
{
label: 'When disabled item',
Example: ({ handler }) => (
<RadioGroup
id="disableditem"
value="2"
onChange={handler}
label="Experience"
>
<RadioItem label="Less than one year" value="0" />
<RadioItem label="1 year" value="1" />
<RadioItem label="2 years" value="2" disabled />
<RadioItem label="3+ years " value="3" />
</RadioGroup>
),
},
],
};
3 changes: 1 addition & 2 deletions lib/components/RadioGroup/RadioItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export interface RadioItemProps
| 'required'
| 'onChange'
| 'id'
| 'disabled'
| 'tone'
| 'size'
> {
Expand Down Expand Up @@ -59,7 +58,7 @@ export const RadioItem = forwardRef<HTMLInputElement, RadioItemProps>(
: undefined
}
size={radioGroupContext.size}
disabled={radioGroupContext.disabled}
disabled={radioGroupContext.disabled || props.disabled}
aria-describedby={radioGroupContext['aria-describedby']}
tabIndex={tababble ? 0 : -1}
inList={true}
Expand Down