-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Conversation
Co-authored-by: Matheus <[email protected]>
@gitstart-twenty Please use SelectableList component and its API to implement it :) |
Alright |
Co-authored-by: v1b3m <[email protected]> Co-authored-by: Matheus <[email protected]>
Co-authored-by: v1b3m <[email protected]> Co-authored-by: Matheus <[email protected]>
Co-authored-by: v1b3m <[email protected]> Co-authored-by: Matheus <[email protected]>
There was a problem hiding this 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); |
There was a problem hiding this comment.
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({ |
There was a problem hiding this comment.
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?.(); |
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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]>
@charlesBochet We're on this |
Co-authored-by: v1b3m <[email protected]> Co-authored-by: Matheus <[email protected]>
}, [navigate, onClick, to, toggleCommandMenu]); | ||
|
||
useEffect(() => { | ||
if (enterClicked && isSelectedItemId) { | ||
onItemClick(); | ||
resetEnterClicked?.(); | ||
} | ||
}, [enterClicked, isSelectedItemId, onItemClick, resetEnterClicked]); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taking a look
@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 |
@gitstart-twenty I'm about to rework the frontend folder architecture. I'm merging this PR as it's adding a feature on IconPicker. |
Fixes #2746