chore: display options menu keyboard nav

This commit is contained in:
Aman Harwara
2023-04-29 00:10:13 +05:30
parent 0ab9006c52
commit e1a47ea884
6 changed files with 28 additions and 16 deletions

View File

@@ -5,6 +5,7 @@ import { useCallback, FunctionComponent, KeyboardEventHandler } from 'react'
import { ApplicationGroup } from '@/Application/ApplicationGroup' import { ApplicationGroup } from '@/Application/ApplicationGroup'
import { AccountMenuPane } from './AccountMenuPane' import { AccountMenuPane } from './AccountMenuPane'
import MenuPaneSelector from './MenuPaneSelector' import MenuPaneSelector from './MenuPaneSelector'
import { KeyboardKey } from '@standardnotes/ui-services'
export type AccountMenuProps = { export type AccountMenuProps = {
viewControllerManager: ViewControllerManager viewControllerManager: ViewControllerManager
@@ -33,16 +34,14 @@ const AccountMenu: FunctionComponent<AccountMenuProps> = ({
const handleKeyDown: KeyboardEventHandler<HTMLDivElement> = useCallback( const handleKeyDown: KeyboardEventHandler<HTMLDivElement> = useCallback(
(event) => { (event) => {
switch (event.key) { if (event.key === KeyboardKey.Escape) {
case 'Escape': if (currentPane === AccountMenuPane.GeneralMenu) {
if (currentPane === AccountMenuPane.GeneralMenu) { closeAccountMenu()
closeAccountMenu() } else if (currentPane === AccountMenuPane.ConfirmPassword) {
} else if (currentPane === AccountMenuPane.ConfirmPassword) { setCurrentPane(AccountMenuPane.Register)
setCurrentPane(AccountMenuPane.Register) } else {
} else { setCurrentPane(AccountMenuPane.GeneralMenu)
setCurrentPane(AccountMenuPane.GeneralMenu) }
}
break
} }
}, },
[closeAccountMenu, currentPane, setCurrentPane], [closeAccountMenu, currentPane, setCurrentPane],

View File

@@ -11,6 +11,7 @@ import {
useSelectStore, useSelectStore,
VisuallyHidden, VisuallyHidden,
} from '@ariakit/react' } from '@ariakit/react'
import { KeyboardKey } from '@standardnotes/ui-services'
type DropdownProps = { type DropdownProps = {
label: string label: string
@@ -59,7 +60,15 @@ const Dropdown = ({ label, value, onChange, items, disabled, fullWidth, classNam
}, [items, onChange, select, value]) }, [items, onChange, select, value])
return ( return (
<div className={classNameOverride.wrapper}> <div
className={classNameOverride.wrapper}
onKeyDown={(event) => {
if (event.key === KeyboardKey.Escape) {
event.stopPropagation()
select.toggle()
}
}}
>
<VisuallyHidden> <VisuallyHidden>
<SelectLabel store={select}>{label}</SelectLabel> <SelectLabel store={select}>{label}</SelectLabel>
</VisuallyHidden> </VisuallyHidden>

View File

@@ -8,6 +8,7 @@ import { PopoverContentProps } from './Types'
import { usePopoverCloseOnClickOutside } from './Utils/usePopoverCloseOnClickOutside' import { usePopoverCloseOnClickOutside } from './Utils/usePopoverCloseOnClickOutside'
import { useDisableBodyScrollOnMobile } from '@/Hooks/useDisableBodyScrollOnMobile' import { useDisableBodyScrollOnMobile } from '@/Hooks/useDisableBodyScrollOnMobile'
import { MediaQueryBreakpoints, useMediaQuery } from '@/Hooks/useMediaQuery' import { MediaQueryBreakpoints, useMediaQuery } from '@/Hooks/useMediaQuery'
import { KeyboardKey } from '@standardnotes/ui-services'
const PositionedPopoverContent = ({ const PositionedPopoverContent = ({
align = 'end', align = 'end',
@@ -88,7 +89,7 @@ const PositionedPopoverContent = ({
ref={setPopoverElement} ref={setPopoverElement}
data-popover={id} data-popover={id}
onKeyDown={(event) => { onKeyDown={(event) => {
if (event.key === 'Escape') { if (event.key === KeyboardKey.Escape) {
event.stopPropagation() event.stopPropagation()
togglePopover?.() togglePopover?.()
if (anchorElement) { if (anchorElement) {

View File

@@ -29,6 +29,7 @@ import { setFloatingElemPosition } from '../../Lexical/Utils/setFloatingElemPosi
import { LexicalPencilFill } from '@standardnotes/icons' import { LexicalPencilFill } from '@standardnotes/icons'
import { IconComponent } from '../../Lexical/../Lexical/Theme/IconComponent' import { IconComponent } from '../../Lexical/../Lexical/Theme/IconComponent'
import { getDOMRangeRect } from '../../Lexical/Utils/getDOMRangeRect' import { getDOMRangeRect } from '../../Lexical/Utils/getDOMRangeRect'
import { KeyboardKey } from '@standardnotes/ui-services'
function FloatingLinkEditor({ editor, anchorElem }: { editor: LexicalEditor; anchorElem: HTMLElement }): JSX.Element { function FloatingLinkEditor({ editor, anchorElem }: { editor: LexicalEditor; anchorElem: HTMLElement }): JSX.Element {
const editorRef = useRef<HTMLDivElement | null>(null) const editorRef = useRef<HTMLDivElement | null>(null)
@@ -148,7 +149,7 @@ function FloatingLinkEditor({ editor, anchorElem }: { editor: LexicalEditor; anc
setLinkUrl(event.target.value) setLinkUrl(event.target.value)
}} }}
onKeyDown={(event) => { onKeyDown={(event) => {
if (event.key === 'Enter') { if (event.key === KeyboardKey.Enter) {
event.preventDefault() event.preventDefault()
if (lastSelection !== null) { if (lastSelection !== null) {
if (linkUrl !== '') { if (linkUrl !== '') {
@@ -156,7 +157,7 @@ function FloatingLinkEditor({ editor, anchorElem }: { editor: LexicalEditor; anc
} }
setEditMode(false) setEditMode(false)
} }
} else if (event.key === 'Escape') { } else if (event.key === KeyboardKey.Escape) {
event.preventDefault() event.preventDefault()
setEditMode(false) setEditMode(false)
} }

View File

@@ -5,6 +5,7 @@ import { TranslateFromTopAnimation, TranslateToTopAnimation } from '@/Constants/
import { useLifecycleAnimation } from '@/Hooks/useLifecycleAnimation' import { useLifecycleAnimation } from '@/Hooks/useLifecycleAnimation'
import { ArrowDownIcon, ArrowUpIcon, CloseIcon, ArrowRightIcon } from '@standardnotes/icons' import { ArrowDownIcon, ArrowUpIcon, CloseIcon, ArrowRightIcon } from '@standardnotes/icons'
import { import {
KeyboardKey,
keyboardStringForShortcut, keyboardStringForShortcut,
SUPER_SEARCH_TOGGLE_CASE_SENSITIVE, SUPER_SEARCH_TOGGLE_CASE_SENSITIVE,
SUPER_SEARCH_TOGGLE_REPLACE_MODE, SUPER_SEARCH_TOGGLE_REPLACE_MODE,
@@ -71,7 +72,7 @@ export const SearchDialog = ({ open, closeDialog }: { open: boolean; closeDialog
<div <div
className="flex flex-col gap-2 py-2 px-2" className="flex flex-col gap-2 py-2 px-2"
onKeyDown={(event) => { onKeyDown={(event) => {
if (event.key === 'Escape') { if (event.key === KeyboardKey.Escape) {
closeDialog() closeDialog()
} }
}} }}

View File

@@ -57,8 +57,9 @@ export const useListKeyboardNavigation = (
const keyDownHandler = useCallback( const keyDownHandler = useCallback(
(e: KeyboardEvent) => { (e: KeyboardEvent) => {
const isFocusInInput = document.activeElement?.tagName === 'INPUT' const isFocusInInput = document.activeElement?.tagName === 'INPUT'
const isFocusInListbox = !!document.activeElement?.closest('[role="listbox"]')
if (isFocusInInput) { if (isFocusInInput || isFocusInListbox) {
return return
} }