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

Add Keyboard navigation on IconPicker #2778

Merged
merged 14 commits into from
Dec 9, 2023
Merged

Add Keyboard navigation on IconPicker #2778

merged 14 commits into from
Dec 9, 2023

Conversation

gitstart-twenty
Copy link
Contributor

Fixes #2746

@charlesBochet
Copy link
Member

@gitstart-twenty Please use SelectableList component and its API to implement it :)

@gitstart-twenty
Copy link
Contributor Author

@gitstart-twenty Please use SelectableList component and its API to implement it :)

Alright

@gitstart-twenty gitstart-twenty changed the title Add Add Keyboard navigation on IconPicker Add Keyboard navigation on IconPicker Dec 1, 2023
Copy link
Member

@charlesBochet charlesBochet left a comment

Choose a reason for hiding this comment

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

@gitstart-twenty I have left comment about performance. Other than that, looks good to me


const setSelectableItemIds = useSetRecoilState(selectableItemIdsState);
const isSelectedItemId = useRecoilValue(isSelectedItemIdSelector);
const selectedItemId = useRecoilValue(selectedItemIdState);
Copy link
Member

Choose a reason for hiding this comment

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

@gitstart-twenty We cannot expose selectedItemId as part of useSelectableList() By doing that, you are listening to any change of selectedItemIdState.
So any component importing useSelectableList will re-render which will considerably impact performances for high level components

@@ -98,6 +100,11 @@ export const CommandMenu = () => {
setSearch(event.target.value);
};

const { selectedItemId } = useSelectableList({
Copy link
Member

Choose a reason for hiding this comment

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

we can't do that (see my comment below)
Instead, within each command menu command we should use isSelectedItemId = useSelectableList(itemId).
This will only listen to the state tied to the itemId

(cmd) => cmd.id === selectedItemId,
);

selectedCommand?.onCommandClick?.();
Copy link
Member

Choose a reason for hiding this comment

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

so this logic should be moved into CommandMenuItem

@@ -77,49 +82,81 @@ export const IconPicker = ({
).slice(0, 25);
}, [icons, searchString, selectedIconKey]);

const iconKeys2d = useMemo(
() => arrayToChunks(iconKeys.slice(), 5),
Copy link
Member

Choose a reason for hiding this comment

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

is the slice() useful?

Co-authored-by: v1b3m <[email protected]>
Co-authored-by: Matheus <[email protected]>
@gitstart-twenty
Copy link
Contributor Author

@charlesBochet We're on this

Comment on lines 54 to 61
}, [navigate, onClick, to, toggleCommandMenu]);

useEffect(() => {
if (enterClicked && isSelectedItemId) {
onItemClick();
resetEnterClicked?.();
}
}, [enterClicked, isSelectedItemId, onItemClick, resetEnterClicked]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @charlesBochet I had some issues implementing this solely from the CommandMenuItem, what do you think of this approach?

Copy link
Member

Choose a reason for hiding this comment

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

Taking a look

@charlesBochet
Copy link
Member

@gitstart-twenty I have implemented it on IconPicker fully and partially on CommandMenu.

On CommandMenu, we should leverage the commandMenuCommandsState better. Our onEnter callback should filter commandMenuCommands based on itemId. Once the right command found, we can trigger onItemClick(onClick, to)

This will work with the static commands but not with the records (companies, people, activities). I think these should be pushed to commandMenuCommands too and then it will work too

@charlesBochet
Copy link
Member

charlesBochet commented Dec 9, 2023

@gitstart-twenty I'm about to rework the frontend folder architecture. I'm merging this PR as it's adding a feature on IconPicker.
Could you please open another PR to refactor CommandMenu so we can implement the onEnter command line 194?

@charlesBochet charlesBochet merged commit 7c40dc7 into main Dec 9, 2023
7 of 8 checks passed
@charlesBochet charlesBochet deleted the TWNTY-2746 branch December 9, 2023 09:45
@charlesBochet charlesBochet mentioned this pull request Dec 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Keyboard navigation on IconPicker
2 participants