Skip to content
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
12 changes: 12 additions & 0 deletions packages/mui-joy/src/Radio/Radio.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ describe('<Radio />', () => {
expect(getByRole('radio')).to.have.property('name', 'bar');
});

it('renders a `role="radio"` with the required attribute', () => {
const { getByRole } = render(<Radio name="bar" required />);

expect(getByRole('radio')).to.have.attribute('required');
});

it('renders a `role="radio"` with the readOnly attribute', () => {
const { getByRole } = render(<Radio name="bar" readOnly />);

expect(getByRole('radio')).to.have.attribute('readonly');
});

it('renders a `role="radio"` with the Unchecked state by default', () => {
const { getByRole } = render(<Radio />);

Expand Down
7 changes: 7 additions & 0 deletions packages/mui-joy/src/Radio/Radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ const Radio = React.forwardRef(function Radio(inProps, ref) {
onChange,
onFocus,
onFocusVisible,
readOnly,
required,
color,
variant = 'outlined',
Expand Down Expand Up @@ -345,6 +346,8 @@ const Radio = React.forwardRef(function Radio(inProps, ref) {
type: 'radio',
id,
name,
readOnly,
required,
value: String(value),
'aria-describedby': formControl?.['aria-describedby'],
},
Expand Down Expand Up @@ -478,6 +481,10 @@ Radio.propTypes /* remove-proptypes */ = {
* @default false;
*/
overlay: PropTypes.bool,
/**
* If `true`, the component is read only.
*/
readOnly: PropTypes.bool,
/**
* If `true`, the `input` element is required.
*/
Expand Down