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
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const FormHorizontal: React.FunctionComponent = () => {
setExperience(experience);
};

const handleOptionChange = (value: string, _event: React.FormEvent<HTMLSelectElement>) => {
const handleOptionChange = (_event: React.FormEvent<HTMLSelectElement>, value: string) => {
setOption(value);
};

Expand Down
18 changes: 4 additions & 14 deletions packages/react-core/src/components/FormSelect/FormSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface FormSelectProps
/** Optional callback for updating when selection gets focus */
onFocus?: (event: React.FormEvent<HTMLSelectElement>) => void;
/** Optional callback for updating when selection changes */
onChange?: (value: string, event: React.FormEvent<HTMLSelectElement>) => void;
onChange?: (event: React.FormEvent<HTMLSelectElement>, value: string) => void;
/** Custom flag to show that the FormSelect requires an associated id or aria-label. */
'aria-label'?: string;
/** Value to overwrite the randomly generated data-ouia-component-id.*/
Expand Down Expand Up @@ -66,22 +66,12 @@ export class FormSelect extends React.Component<FormSelectProps, { ouiaStateId:
};

handleChange = (event: any) => {
this.props.onChange(event.currentTarget.value, event);
this.props.onChange(event, event.currentTarget.value);
};

render() {
const {
children,
className,
value,
validated,
isDisabled,
isRequired,
isIconSprite,
ouiaId,
ouiaSafe,
...props
} = this.props;
const { children, className, value, validated, isDisabled, isRequired, isIconSprite, ouiaId, ouiaSafe, ...props } =
this.props;
/* find selected option and get placeholder flag */
const selectedOption = React.Children.toArray(children).find((option: any) => option.props.value === value) as any;
const isSelectedPlaceholder = selectedOption && selectedOption.props.isPlaceholder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,6 @@ describe('FormSelect', () => {
await user.selectOptions(screen.getByLabelText('Some label'), 'Mr');

expect(myMock).toHaveBeenCalled();
expect(myMock.mock.calls[0][0]).toEqual('mr');
expect(myMock.mock.calls[0][1]).toEqual('mr');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FormSelect, FormSelectOption } from '@patternfly/react-core';
export const FormSelectBasic: React.FunctionComponent = () => {
const [formSelectValue, setFormSelectValue] = React.useState('mrs');

const onChange = (value: string) => {
const onChange = (_event: React.FormEvent<HTMLSelectElement>, value: string) => {
setFormSelectValue(value);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FormSelect, FormSelectOption } from '@patternfly/react-core';
export const FormSelectDisabled: React.FunctionComponent = () => {
const [formSelectValue, setFormSelectValue] = React.useState('mrs');

const onChange = (value: string) => {
const onChange = (_event: React.FormEvent<HTMLSelectElement>, value: string) => {
setFormSelectValue(value);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FormSelect, FormSelectOption, FormSelectOptionGroup } from '@patternfly
export const FormSelectGrouped: React.FunctionComponent = () => {
const [formSelectValue, setFormSelectValue] = React.useState('2');

const onChange = (value: string) => {
const onChange = (_event: React.FormEvent<HTMLSelectElement>, value: string) => {
setFormSelectValue(value);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const FormSelectIconSpriteVariant: React.FunctionComponent = () => {
const [validated, setValidated] = React.useState<ValidatedOptions>(ValidatedOptions.default);
const [helperText, setHelperText] = React.useState('');

const onChange = (value: string) => {
const onChange = (_event: React.FormEvent<HTMLSelectElement>, value: string) => {
if (value === '3') {
setFormSelectValue(value);
setValidated(ValidatedOptions.success);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const FormSelectValidated: React.FunctionComponent = () => {
setTimeout(callback, 2000);
};

const onChange = (value: string) => {
const onChange = (_event: React.FormEvent<HTMLSelectElement>, value: string) => {
setFormValue(value);
setValidated(ValidatedOptions.default);
setHelperText('Validating...');
Expand Down