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

fix(Radio): updated param order for onChange #8965

Merged
merged 2 commits into from
Apr 20, 2023
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
4 changes: 2 additions & 2 deletions packages/react-core/src/components/Radio/Radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface RadioProps
/** Name for group of radios */
name: string;
/** A callback for when the radio selection changes. */
onChange?: (checked: boolean, event: React.FormEvent<HTMLInputElement>) => void;
onChange?: (event: React.FormEvent<HTMLInputElement>, checked: boolean) => void;
/** Aria label for the radio. */
'aria-label'?: string;
/** Description text of the radio. */
Expand Down Expand Up @@ -62,7 +62,7 @@ export class Radio extends React.Component<RadioProps, { ouiaStateId: string }>
}

handleChange = (event: React.FormEvent<HTMLInputElement>) => {
this.props.onChange(event.currentTarget.checked, event);
this.props.onChange(event, event.currentTarget.checked);
};

render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('Radio', () => {
render(<Radio id="check" {...props} aria-label="check" name="check" />);

await user.click(screen.getByRole('radio'));
expect(props.onChange).toHaveBeenCalledWith(true, expect.any(Object));
expect(props.onChange).toHaveBeenCalledWith(expect.any(Object), true);
});

test('Radio description', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,15 @@ class ProgressiveWizard extends React.Component {
<Radio
value="Create"
isChecked={getStartedStepRadio === 'Create'}
onChange={(_, event) => this.setState({ getStartedStepRadio: event.currentTarget.value })}
onChange={(event) => this.setState({ getStartedStepRadio: event.currentTarget.value })}
label="Create a new thing"
name="radio-step-start"
id="radio-step-start-1"
/>{' '}
<Radio
value="Update"
isChecked={getStartedStepRadio === 'Update'}
onChange={(_, event) => this.setState({ getStartedStepRadio: event.currentTarget.value })}
onChange={(event) => this.setState({ getStartedStepRadio: event.currentTarget.value })}
label="Update an existing thing"
name="radio-step-start"
id="radio-step-start-2"
Expand All @@ -250,15 +250,15 @@ class ProgressiveWizard extends React.Component {
<Radio
value="Quick"
isChecked={createStepRadio === 'Quick'}
onChange={(_, event) => this.setState({ createStepRadio: event.currentTarget.value })}
onChange={(event) => this.setState({ createStepRadio: event.currentTarget.value })}
label="Quick create"
name="radio-step-create"
id="radio-step-create-1"
/>{' '}
<Radio
value="Custom"
isChecked={createStepRadio === 'Custom'}
onChange={(_, event) => this.setState({ createStepRadio: event.currentTarget.value })}
onChange={(event) => this.setState({ createStepRadio: event.currentTarget.value })}
label="Custom create"
name="radio-step-create"
id="radio-step-create-2"
Expand All @@ -273,15 +273,15 @@ class ProgressiveWizard extends React.Component {
<Radio
value="Quick"
isChecked={updateStepRadio === 'Quick'}
onChange={(_, event) => this.setState({ updateStepRadio: event.currentTarget.value })}
onChange={(event) => this.setState({ updateStepRadio: event.currentTarget.value })}
label="Quick update"
name="radio-step-update"
id="radio-step-update-1"
/>{' '}
<Radio
value="Custom"
isChecked={updateStepRadio === 'Custom'}
onChange={(_, event) => this.setState({ updateStepRadio: event.currentTarget.value })}
onChange={(event) => this.setState({ updateStepRadio: event.currentTarget.value })}
label="Custom update"
name="radio-step-update"
id="radio-step-update-2"
Expand Down
4 changes: 2 additions & 2 deletions packages/react-integration/demo-app-ts/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class App extends React.Component<{}, AppState> {
label={`Light theme`}
name="light-theme"
isChecked={!isDarkTheme}
onChange={checked => checked && this.onThemeSelect(false)}
onChange={(_event: React.FormEvent<HTMLInputElement>, checked: boolean) => checked && this.onThemeSelect(false)}
/>
</PageHeaderToolsItem>
<PageHeaderToolsItem>
Expand All @@ -108,7 +108,7 @@ class App extends React.Component<{}, AppState> {
aria-label="Dark theme"
name="dark-theme"
isChecked={isDarkTheme}
onChange={checked => checked && this.onThemeSelect(true)}
onChange={(_event: React.FormEvent<HTMLInputElement>, checked: boolean) => checked && this.onThemeSelect(true)}
/>
</PageHeaderToolsItem>
</PageHeaderToolsGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export class RadioDemo extends Component {
value: '4'
};

handleChange = (_checked: boolean, event: React.FormEvent<HTMLInputElement>) => {
handleChange = (event: React.FormEvent<HTMLInputElement>) => {
const { value } = event.currentTarget;
this.setState({ value });
};
Expand Down