feat: Improved keyboard navigation for tags and smart views. Tags can now be expanded/closed using left and right arrow keys.
This commit is contained in:
@@ -86,16 +86,26 @@ export const TagsListItem: FunctionComponent<Props> = observer(
|
|||||||
setTitle(tag.title || '')
|
setTitle(tag.title || '')
|
||||||
}, [setTitle, tag])
|
}, [setTitle, tag])
|
||||||
|
|
||||||
|
const setTagExpanded = useCallback(
|
||||||
|
(expanded: boolean) => {
|
||||||
|
if (!hasChildren) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
setShowChildren(expanded)
|
||||||
|
if (!navigationController.isSearching) {
|
||||||
|
navigationController.setExpanded(tag, expanded)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[hasChildren, navigationController, tag],
|
||||||
|
)
|
||||||
|
|
||||||
const toggleChildren = useCallback(
|
const toggleChildren = useCallback(
|
||||||
(e?: MouseEvent) => {
|
(e?: MouseEvent) => {
|
||||||
e?.stopPropagation()
|
e?.stopPropagation()
|
||||||
const shouldShowChildren = !showChildren
|
const shouldShowChildren = !showChildren
|
||||||
setShowChildren(shouldShowChildren)
|
setTagExpanded(shouldShowChildren)
|
||||||
if (!navigationController.isSearching) {
|
|
||||||
navigationController.setExpanded(tag, shouldShowChildren)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
[showChildren, tag, navigationController],
|
[showChildren, setTagExpanded],
|
||||||
)
|
)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -285,6 +295,10 @@ export const TagsListItem: FunctionComponent<Props> = observer(
|
|||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
if (event.key === KeyboardKey.Enter || event.key === KeyboardKey.Space) {
|
if (event.key === KeyboardKey.Enter || event.key === KeyboardKey.Space) {
|
||||||
selectCurrentTag().catch(console.error)
|
selectCurrentTag().catch(console.error)
|
||||||
|
} else if (event.key === KeyboardKey.Left) {
|
||||||
|
setTagExpanded(false)
|
||||||
|
} else if (event.key === KeyboardKey.Right) {
|
||||||
|
setTagExpanded(true)
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
ref={tagRef}
|
ref={tagRef}
|
||||||
|
|||||||
Reference in New Issue
Block a user