Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
[Autocomplete] Move event params to the end
  • Loading branch information
Marco Moretti committed Apr 22, 2020
commit 54c5e12bde520654342bb77eb0e784d76a8477cb
24 changes: 12 additions & 12 deletions packages/material-ui-lab/src/Autocomplete/Autocomplete.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1564,9 +1564,9 @@ describe('<Autocomplete />', () => {
/>,
);
expect(handleChange.callCount).to.equal(1);
expect(handleChange.args[0][0]).to.equal(null);
expect(handleChange.args[0][1]).to.equal(options[0]);
expect(handleChange.args[0][2]).to.equal('auto');
expect(handleChange.args[0][0]).to.equal(options[0]);
expect(handleChange.args[0][1]).to.equal('auto');
expect(handleChange.args[0][2]).to.equal(undefined);
});

it('should support keyboard event', () => {
Expand All @@ -1582,14 +1582,14 @@ describe('<Autocomplete />', () => {
);
fireEvent.keyDown(document.activeElement, { key: 'ArrowDown' });
expect(handleChange.callCount).to.equal(1);
expect(handleChange.args[0][0]).to.not.equal(null);
expect(handleChange.args[0][1]).to.equal(options[0]);
expect(handleChange.args[0][2]).to.equal('keyboard');
expect(handleChange.args[0][0]).to.equal(options[0]);
expect(handleChange.args[0][1]).to.equal('keyboard');
expect(handleChange.args[0][2]).to.not.equal(undefined);
fireEvent.keyDown(document.activeElement, { key: 'ArrowDown' });
expect(handleChange.callCount).to.equal(2);
expect(handleChange.args[1][0]).to.not.equal(null);
expect(handleChange.args[1][1]).to.equal(options[1]);
expect(handleChange.args[1][2]).to.equal('keyboard');
expect(handleChange.args[1][0]).to.equal(options[1]);
expect(handleChange.args[1][1]).to.equal('keyboard');
expect(handleChange.args[1][2]).to.not.equal(undefined);
});

it('should support mouse event', () => {
Expand All @@ -1606,9 +1606,9 @@ describe('<Autocomplete />', () => {
const firstOption = getAllByRole('option')[0];
fireEvent.mouseOver(firstOption);
expect(handleChange.callCount).to.equal(1);
expect(handleChange.args[0][0]).to.not.equal(null);
expect(handleChange.args[0][1]).to.equal(options[0]);
expect(handleChange.args[0][2]).to.equal('mouse');
expect(handleChange.args[0][0]).to.equal(options[0]);
expect(handleChange.args[0][1]).to.equal('mouse');
expect(handleChange.args[0][2]).to.not.equal(undefined);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,9 @@ export interface UseAutocompleteCommonProps<T> {
* @param {string} reason Can be: `"keyboard"`, `"auto"`, `"mouse"`.
*/
onHighlightChange?: (
event?: React.ChangeEvent<{}>,
// @ts-ignore
option: T,
reason: AutocompleteHighlightChangeReason
reason: AutocompleteHighlightChangeReason,
event?: React.ChangeEvent<{}>
) => void;
/**
* Control the popup` open state.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export default function useAutocomplete(props) {
const defaultHighlighted = autoHighlight ? 0 : -1;
const highlightedIndexRef = React.useRef(defaultHighlighted);

const setHighlightedIndex = useEventCallback((index, changeReason = 'auto', event = null) => {
const setHighlightedIndex = useEventCallback((index, changeReason = 'auto', event) => {
highlightedIndexRef.current = index;
// does the index exist?
if (index === -1) {
Expand Down Expand Up @@ -159,7 +159,7 @@ export default function useAutocomplete(props) {

option.setAttribute('data-focus', 'true');
if (onHighlightChange && index !== -1) {
onHighlightChange(event, options[index], changeReason);
onHighlightChange(options[index], changeReason, event);
}
// Scroll active descendant into view.
// Logic copied from https://www.w3.org/TR/wai-aria-practices/examples/listbox/js/listbox.js
Expand Down Expand Up @@ -336,7 +336,7 @@ export default function useAutocomplete(props) {
}

const changeHighlightedIndex = useEventCallback(
(diff, direction, changeReason = 'auto', event = null) => {
(diff, direction, changeReason = 'auto', event) => {
if (!popupOpen) {
return;
}
Expand Down