Skip to content

Commit

Permalink
[Select], [TablePagination] Use more descriptive parameter names (#37064
Browse files Browse the repository at this point in the history
)
  • Loading branch information
michaldudak authored May 9, 2023
1 parent e916b0f commit 8acb5dd
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default function UnstyledSelectControlled() {
const [value, setValue] = React.useState(10);
return (
<div>
<CustomSelect value={value} onChange={(e, newValue) => setValue(newValue)}>
<CustomSelect value={value} onChange={(_, newValue) => setValue(newValue)}>
<StyledOption value={10}>Ten</StyledOption>
<StyledOption value={20}>Twenty</StyledOption>
<StyledOption value={30}>Thirty</StyledOption>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default function UnstyledSelectControlled() {
const [value, setValue] = React.useState<number | null>(10);
return (
<div>
<CustomSelect value={value} onChange={(e, newValue) => setValue(newValue)}>
<CustomSelect value={value} onChange={(_, newValue) => setValue(newValue)}>
<StyledOption value={10}>Ten</StyledOption>
<StyledOption value={20}>Twenty</StyledOption>
<StyledOption value={30}>Thirty</StyledOption>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<CustomSelect value={value} onChange={(e, newValue) => setValue(newValue)}>
<CustomSelect value={value} onChange={(_, newValue) => setValue(newValue)}>
<StyledOption value={10}>Ten</StyledOption>
<StyledOption value={20}>Twenty</StyledOption>
<StyledOption value={30}>Thirty</StyledOption>
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-base/src/Select/Select.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export interface SelectOwnProps<OptionValue extends {}, Multiple extends boolean
* Callback fired when an option is selected.
*/
onChange?: (
e: React.MouseEvent | React.KeyboardEvent | React.FocusEvent | null,
event: React.MouseEvent | React.KeyboardEvent | React.FocusEvent | null,
value: SelectValue<OptionValue, Multiple>,
) => void;
/**
Expand Down
4 changes: 2 additions & 2 deletions packages/mui-base/src/TablePagination/TablePagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ const TablePagination = React.forwardRef(function TablePagination<
additionalProps: {
value: rowsPerPage,
id: selectId,
onChange: (e: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>) =>
onRowsPerPageChange && onRowsPerPageChange(e),
onChange: (event: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>) =>
onRowsPerPageChange && onRowsPerPageChange(event),
'aria-label': rowsPerPage.toString(),
'aria-labelledby': [labelId, selectId].filter(Boolean).join(' ') || undefined,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export type TablePaginationSelectSlotProps = {
children?: React.ReactNode;
className?: string;
id?: string;
onChange: (e: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>) => void;
onChange: (event: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>) => void;
ownerState: TablePaginationOwnerState;
value: React.SelectHTMLAttributes<HTMLSelectElement>['value'];
};
Expand Down
4 changes: 2 additions & 2 deletions packages/mui-base/src/useSelect/useSelect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@ function useSelect<OptionValue, Multiple extends boolean = false>(
);

const handleStateChange = React.useCallback(
(e: React.SyntheticEvent | null, field: string, fieldValue: any) => {
(event: React.SyntheticEvent | null, field: string, fieldValue: any) => {
if (field === 'open') {
onOpenChange?.(fieldValue as boolean);
if (fieldValue === false && e?.type !== 'blur') {
if (fieldValue === false && event?.type !== 'blur') {
buttonRef.current?.focus();
}
}
Expand Down
17 changes: 9 additions & 8 deletions packages/mui-base/src/utils/useSlotProps.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,15 @@ describe('useSlotProps', () => {
const externalClickHandler = spy();
const externalForwardedClickHandler = spy();

const createInternalClickHandler = (otherHandlers: EventHandlers) => (e: React.MouseEvent) => {
expect(otherHandlers).to.deep.equal({
onClick: externalClickHandler,
});

otherHandlers.onClick(e);
internalClickHandler(e);
};
const createInternalClickHandler =
(otherHandlers: EventHandlers) => (event: React.MouseEvent) => {
expect(otherHandlers).to.deep.equal({
onClick: externalClickHandler,
});

otherHandlers.onClick(event);
internalClickHandler(event);
};

// usually provided by the hook:
const getSlotProps = (otherHandlers: EventHandlers) => ({
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-joy/src/Select/SelectProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export type SelectOwnProps<TValue extends {}> = SelectStaticProps &
* Callback fired when an option is selected.
*/
onChange?: (
e: React.MouseEvent | React.KeyboardEvent | React.FocusEvent | null,
event: React.MouseEvent | React.KeyboardEvent | React.FocusEvent | null,
value: TValue | null,
) => void;
/**
Expand Down

0 comments on commit 8acb5dd

Please sign in to comment.