-
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
24e469f
Add Add Keyboard navigation on IconPicker
gitstart-twenty 0fbc12a
Merge commit '2dcce31edea59c848fa7c12113eeaf5b2ac4b723' of https://gi…
gitstart-twenty 75f95b7
Add Keyboard navigation on IconPicker
gitstart-twenty 83ad418
Merge commit '1616ea6c4f654f7afbe17aea4d1cd71b151425d9' of https://gi…
gitstart-twenty 1f639a0
Add Keyboard navigation on IconPicker
gitstart-twenty 68dbfad
Merge commit '69f48ea3302cb837675be67146b488b74e7b980e' of https://gi…
gitstart-twenty 20a7deb
Add Keyboard navigation on IconPicker
gitstart-twenty ba9843b
Merge main
gitstart-twenty 74ce8e2
Merge commit 'b68f5cda97f4aed9cb569a42bbe76320bbd56346' of https://gi…
gitstart-twenty f6be255
Refactor according to review
gitstart-twenty 7453064
Merge branch 'main' into TWNTY-2746
charlesBochet 4c57b4d
Implement IconPicker
charlesBochet 5cf9d75
Merge branch 'main' into TWNTY-2746
charlesBochet 0edc07a
Remove onEnter clicked
charlesBochet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
front/src/modules/command-menu/components/CommandMenuSelectableListEffect.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { useMemo, useState } from 'react'; | ||
import styled from '@emotion/styled'; | ||
import { Key } from 'ts-key-enum'; | ||
|
||
import { IconComponent } from '@/ui/display/icon/types/IconComponent'; | ||
import { Dropdown } from '@/ui/layout/dropdown/components/Dropdown'; | ||
|
@@ -9,6 +10,10 @@ import { DropdownMenuSearchInput } from '@/ui/layout/dropdown/components/Dropdow | |
import { DropdownMenuSeparator } from '@/ui/layout/dropdown/components/DropdownMenuSeparator'; | ||
import { useDropdown } from '@/ui/layout/dropdown/hooks/useDropdown'; | ||
import { DropdownScope } from '@/ui/layout/dropdown/scopes/DropdownScope'; | ||
import { SelectableList } from '@/ui/layout/selectable-list/components/SelectableList'; | ||
import { useSelectableList } from '@/ui/layout/selectable-list/hooks/useSelectableList'; | ||
import { useScopedHotkeys } from '@/ui/utilities/hotkey/hooks/useScopedHotkeys'; | ||
import { arrayToChunks } from '~/utils/array/array-to-chunks'; | ||
|
||
import { IconButton, IconButtonVariant } from '../button/components/IconButton'; | ||
import { LightIconButton } from '../button/components/LightIconButton'; | ||
|
@@ -79,6 +84,32 @@ 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 commentThe reason will be displayed to describe this comment to others. Learn more. is the slice() useful? |
||
[iconKeys], | ||
); | ||
|
||
const { selectedItemId } = useSelectableList({ | ||
selectableListId: 'icon-list', | ||
}); | ||
|
||
const selectedItem = selectedItemId ?? selectedIconKey; | ||
|
||
useScopedHotkeys( | ||
Key.Enter, | ||
() => { | ||
if (selectedItem) { | ||
const itemIndex = iconKeys.indexOf(selectedItem); | ||
|
||
if (itemIndex === -1) | ||
onChange({ iconKey: selectedItem, Icon: icons[itemIndex] }); | ||
closeDropdown(); | ||
} | ||
}, | ||
IconPickerHotkeyScope.IconPicker, | ||
[selectedItem], | ||
); | ||
|
||
return ( | ||
<DropdownScope dropdownScopeId={dropdownScopeId}> | ||
<div className={className}> | ||
|
@@ -87,42 +118,48 @@ export const IconPicker = ({ | |
clickableComponent={ | ||
<IconButton | ||
disabled={disabled} | ||
Icon={selectedIconKey ? icons[selectedIconKey] : IconApps} | ||
Icon={selectedItem ? icons[selectedItem] : IconApps} | ||
variant={variant} | ||
/> | ||
} | ||
dropdownMenuWidth={176} | ||
dropdownComponents={ | ||
<DropdownMenu width={176}> | ||
<DropdownMenuSearchInput | ||
placeholder="Search icon" | ||
autoFocus | ||
onChange={(event) => setSearchString(event.target.value)} | ||
/> | ||
<DropdownMenuSeparator /> | ||
<DropdownMenuItemsContainer> | ||
{isLoading ? ( | ||
<DropdownMenuSkeletonItem /> | ||
) : ( | ||
<StyledMenuIconItemsContainer> | ||
{iconKeys.map((iconKey) => ( | ||
<StyledLightIconButton | ||
key={iconKey} | ||
aria-label={convertIconKeyToLabel(iconKey)} | ||
isSelected={selectedIconKey === iconKey} | ||
size="medium" | ||
title={iconKey} | ||
Icon={icons[iconKey]} | ||
onClick={() => { | ||
onChange({ iconKey, Icon: icons[iconKey] }); | ||
closeDropdown(); | ||
}} | ||
/> | ||
))} | ||
</StyledMenuIconItemsContainer> | ||
)} | ||
</DropdownMenuItemsContainer> | ||
</DropdownMenu> | ||
<SelectableList | ||
selectableListId="icon-list" | ||
selectableItemIds={iconKeys2d} | ||
hotkeyScope={IconPickerHotkeyScope.IconPicker} | ||
> | ||
<DropdownMenu width={176}> | ||
<DropdownMenuSearchInput | ||
placeholder="Search icon" | ||
autoFocus | ||
onChange={(event) => setSearchString(event.target.value)} | ||
/> | ||
<DropdownMenuSeparator /> | ||
<DropdownMenuItemsContainer> | ||
{isLoading ? ( | ||
<DropdownMenuSkeletonItem /> | ||
) : ( | ||
<StyledMenuIconItemsContainer> | ||
{iconKeys.map((iconKey) => ( | ||
<StyledLightIconButton | ||
key={iconKey} | ||
aria-label={convertIconKeyToLabel(iconKey)} | ||
isSelected={selectedItem === iconKey} | ||
size="medium" | ||
title={iconKey} | ||
Icon={icons[iconKey]} | ||
onClick={() => { | ||
onChange({ iconKey, Icon: icons[iconKey] }); | ||
closeDropdown(); | ||
}} | ||
/> | ||
))} | ||
</StyledMenuIconItemsContainer> | ||
)} | ||
</DropdownMenuItemsContainer> | ||
</DropdownMenu> | ||
</SelectableList> | ||
} | ||
onClickOutside={onClickOutside} | ||
onClose={() => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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