Skip to content

Commit

Permalink
[Radio][Joy UI] spread readOnly and required to input (mui#34478)
Browse files Browse the repository at this point in the history
  • Loading branch information
siriwatknp authored and alexfauquette committed Oct 14, 2022
1 parent 9d13f63 commit d23b891
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/mui-joy/src/Radio/Radio.test.js
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
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

0 comments on commit d23b891

Please sign in to comment.