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

Refactor InputDropdown and Dropdown #60

Merged
merged 12 commits into from
Nov 25, 2021
Merged

Conversation

nmanu1
Copy link
Contributor

@nmanu1 nmanu1 commented Nov 24, 2021

Introduces a DropdownSection component that handles the logic of navigating the focus between options within that section of the dropdown. InputDropdown now only handles navigation between which section is focused and it no longer controls how the dropdown is structured.

J=SLAP-1722
TEST=manual

Check that the search bar in the sample-app behaves as expected

@coveralls
Copy link

coveralls commented Nov 24, 2021

Coverage Status

Coverage remained the same at 75.532% when pulling d4c7c4c on dev/dropdown-section-refactor into fefc014 on main.

}
}, [focusStatus]);

useEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this useEffect be group with the useEffect above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the event listener needs to be added whenever the section is active, not just when it first becomes active (like the first useEffect). I tried combining them, but then only the first keydown event is registered

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are cloning the element each time when section is set active right? So wouldn't it be first render of the newly clone section be enough to setup the listener?

function onLeaveSectionFocus(focusNext: boolean) {
if (focusedSectionIndex === undefined && focusNext) {
dispatch({ type: 'FocusSection', newIndex: 0 });
} else if (focusedSectionIndex !== undefined && focusedSectionIndex < numSections - 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think focusedSectionIndex !== undefined can be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I restructured it, so now I think the focusedSectionIndex !== undefined should stay

Comment on lines 107 to 122
} else if (focusedSectionIndex !== undefined && focusedSectionIndex < numSections - 1) {
let newSectionIndex: number | undefined = focusNext ? focusedSectionIndex + 1 : focusedSectionIndex - 1;
if (newSectionIndex < 0) {
newSectionIndex = undefined;
onInputChange(latestUserInput);
}
dispatch({ type: 'FocusSection', newIndex: newSectionIndex });
} else if (focusedSectionIndex === numSections - 1 && !focusNext) {
let newSectionIndex: number | undefined = focusedSectionIndex - 1;
if (newSectionIndex < 0) {
newSectionIndex = undefined;
}
dispatch({ type: 'FocusSection', newIndex: newSectionIndex });
}
}

Copy link
Contributor

@yen-tt yen-tt Nov 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a bit difficult to follow, can we refactor this top level else if to something like this?

const moveToNextSection = focusNext and NOT last section;
const moveToPreviousSection = !focusNext and NOT first section;
else if it's moveToNextSection OR movePreviousSection
	update input + move to new section
else if it's (!focusNext and first section) //want to move up to search bar
	update to latest input + section index as undefined

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I restructured this a little. Does it make more sense now?

Copy link
Member

@cea2aj cea2aj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@nmanu1 nmanu1 requested a review from cea2aj November 24, 2021 23:49
@nmanu1 nmanu1 merged commit 53a3aae into main Nov 25, 2021
@nmanu1 nmanu1 deleted the dev/dropdown-section-refactor branch December 2, 2021 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants