-
Notifications
You must be signed in to change notification settings - Fork 503
♿️(frontend) fix subdoc opening and emoji pick focus #1745
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
base: main
Are you sure you want to change the base?
Changes from all commits
e86cd39
110bc42
d66039f
28d99e2
841afe0
2560f59
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ import { | |
| useTrans, | ||
| } from '@/docs/doc-management'; | ||
| import { useLeftPanelStore } from '@/features/left-panel'; | ||
| import { useKeyboardActivation } from '@/hooks/useKeyboardActivation'; | ||
| import { useResponsiveStore } from '@/stores'; | ||
|
|
||
| import SubPageIcon from './../assets/sub-page-logo.svg'; | ||
|
|
@@ -97,6 +98,7 @@ export const DocSubPageItem = (props: TreeViewNodeProps<Doc>) => { | |
| const isDisabled = !!doc.deleted_at; | ||
| const actionsRef = useRef<HTMLDivElement>(null); | ||
| const buttonOptionRef = useRef<HTMLDivElement | null>(null); | ||
| const isActive = node.isFocused; | ||
|
|
||
| const handleKeyDown = (e: React.KeyboardEvent) => { | ||
| // F2: focus first action button | ||
|
|
@@ -108,6 +110,14 @@ export const DocSubPageItem = (props: TreeViewNodeProps<Doc>) => { | |
| } | ||
| }; | ||
|
|
||
| useKeyboardActivation( | ||
| ['Enter'], | ||
| isActive && !menuOpen, | ||
| handleActivate, | ||
| true, | ||
| '.c__tree-view', | ||
| ); | ||
|
|
||
|
Comment on lines
+113
to
+120
Collaborator
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. I don't think you need it anymore, this commit (suitenumerique/ui-kit@c121fdd#diff-69b4765cf5a180b5d5c2157eb0132487a6c0b7b7fb1dc379250ce110ac162e2eR27) adds
Collaborator
Author
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. has talk together, waiting for updates on your side because change @gouvfr-lasuite/ui-kit": "0.18.4" to .5 or .6 seems to break |
||
| const handleActionsOpenChange = (isOpen: boolean) => { | ||
| setMenuOpen(isOpen); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| export * from './useKeyboardAction'; | ||
| export * from './useKeyboardActivation'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { useEffect } from 'react'; | ||
|
|
||
| export const useKeyboardActivation = ( | ||
| keys: string[], | ||
| enabled: boolean, | ||
| action: () => void, | ||
| capture = false, | ||
| selector: string, | ||
| ) => { | ||
| useEffect(() => { | ||
| if (!enabled) { | ||
| return; | ||
| } | ||
| const onKeyDown = (e: KeyboardEvent) => { | ||
| if (keys.includes(e.key)) { | ||
| // Ignore if focus is on interactive elements (emoji picker button, actions menu, etc.) | ||
| const target = e.target as HTMLElement | null; | ||
| if ( | ||
| target?.closest('.--docs--doc-icon') || | ||
| target?.closest('.light-doc-item-actions') || | ||
| target?.closest('button') || | ||
| target?.closest('[role="menu"]') || | ||
| target?.closest('[role="menuitem"]') | ||
| ) { | ||
| return; | ||
| } | ||
|
|
||
| e.preventDefault(); | ||
| action(); | ||
| } | ||
| }; | ||
| const treeEl = document.querySelector<HTMLElement>(selector); | ||
| if (!treeEl) { | ||
| return; | ||
| } | ||
| treeEl.addEventListener('keydown', onKeyDown, capture); | ||
| return () => { | ||
| treeEl.removeEventListener('keydown', onKeyDown, capture); | ||
| }; | ||
| }, [keys, enabled, action, capture, selector]); | ||
| }; |
Uh oh!
There was an error while loading. Please reload this page.