mirror of
https://github.com/suitenumerique/meet.git
synced 2026-08-31 12:47:58 +00:00
♿️(frontend) close side panel with Escape key
useEscapeToClose: close panel on Escape, restore focus, let chat input bubble
This commit is contained in:
@@ -24,6 +24,7 @@ and this project adheres to
|
|||||||
- ♻️(frontend) inline model weights to avoid loading them from remote
|
- ♻️(frontend) inline model weights to avoid loading them from remote
|
||||||
- ♻️(frontend) inline MediaPipe WASM modules to avoid loading from remote
|
- ♻️(frontend) inline MediaPipe WASM modules to avoid loading from remote
|
||||||
- ⬆️(frontend) upgrade posthog-js from 1.387.0 to 1.391.2
|
- ⬆️(frontend) upgrade posthog-js from 1.387.0 to 1.391.2
|
||||||
|
- ♿️(frontend) close side panel with Escape key #1507
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import { Info } from './Info'
|
|||||||
import { HStack } from '@/styled-system/jsx'
|
import { HStack } from '@/styled-system/jsx'
|
||||||
import { useReactionsToolbar } from '@/features/reactions/hooks/useReactionsToolbar'
|
import { useReactionsToolbar } from '@/features/reactions/hooks/useReactionsToolbar'
|
||||||
import { useRestoreFocus } from '@/hooks/useRestoreFocus'
|
import { useRestoreFocus } from '@/hooks/useRestoreFocus'
|
||||||
|
import { useEscapeToClose } from '@/hooks/useEscapeToClose'
|
||||||
|
|
||||||
type StyledSidePanelProps = {
|
type StyledSidePanelProps = {
|
||||||
title: string
|
title: string
|
||||||
@@ -188,21 +189,25 @@ export const SidePanel = () => {
|
|||||||
focusAside()
|
focusAside()
|
||||||
}, [activePanelId, focusAside])
|
}, [activePanelId, focusAside])
|
||||||
|
|
||||||
|
const closePanel = useCallback(() => {
|
||||||
|
layoutStore.activePanelId = null
|
||||||
|
layoutStore.activeSubPanelId = null
|
||||||
|
}, [])
|
||||||
|
|
||||||
useRestoreFocus(isSidePanelOpen, {
|
useRestoreFocus(isSidePanelOpen, {
|
||||||
onOpened: handlePanelOpened,
|
onOpened: handlePanelOpened,
|
||||||
preventScroll: true,
|
preventScroll: true,
|
||||||
activeKey: activePanelId,
|
activeKey: activePanelId,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
useEscapeToClose(isSidePanelOpen, asideRef, closePanel)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledSidePanel
|
<StyledSidePanel
|
||||||
ref={asideRef}
|
ref={asideRef}
|
||||||
title={title}
|
title={title}
|
||||||
ariaLabel={t('ariaLabel', { title })}
|
ariaLabel={t('ariaLabel', { title })}
|
||||||
onClose={() => {
|
onClose={closePanel}
|
||||||
layoutStore.activePanelId = null
|
|
||||||
layoutStore.activeSubPanelId = null
|
|
||||||
}}
|
|
||||||
closeButtonTooltip={t('closeButton', {
|
closeButtonTooltip={t('closeButton', {
|
||||||
content: t(`content.${activeSubPanelId || activePanelId}`),
|
content: t(`content.${activeSubPanelId || activePanelId}`),
|
||||||
})}
|
})}
|
||||||
|
|||||||
@@ -35,6 +35,11 @@ export const ChatInput = ({
|
|||||||
if (!isDisabled) handleSubmit()
|
if (!isDisabled) handleSubmit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
||||||
|
if (e.key !== 'Escape') e.stopPropagation()
|
||||||
|
submitOnEnter(e)
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const resize = () => {
|
const resize = () => {
|
||||||
if (!inputRef.current) return
|
if (!inputRef.current) return
|
||||||
@@ -79,10 +84,7 @@ export const ChatInput = ({
|
|||||||
>
|
>
|
||||||
<TextArea
|
<TextArea
|
||||||
ref={inputRef}
|
ref={inputRef}
|
||||||
onKeyDown={(e) => {
|
onKeyDown={handleKeyDown}
|
||||||
e.stopPropagation()
|
|
||||||
submitOnEnter(e)
|
|
||||||
}}
|
|
||||||
onKeyUp={(e) => e.stopPropagation()}
|
onKeyUp={(e) => e.stopPropagation()}
|
||||||
placeholder={t('textArea.placeholder')}
|
placeholder={t('textArea.placeholder')}
|
||||||
value={text}
|
value={text}
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import { useEffect, useRef, type RefObject } from 'react'
|
||||||
|
|
||||||
|
export const useEscapeToClose = (
|
||||||
|
isActive: boolean,
|
||||||
|
containerRef: RefObject<HTMLElement | null>,
|
||||||
|
onClose: () => void
|
||||||
|
) => {
|
||||||
|
const onCloseRef = useRef(onClose)
|
||||||
|
useEffect(() => {
|
||||||
|
onCloseRef.current = onClose
|
||||||
|
})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isActive) return
|
||||||
|
|
||||||
|
const handleKeyDown = (e: KeyboardEvent) => {
|
||||||
|
if (e.key !== 'Escape') return
|
||||||
|
if (!containerRef.current?.contains(document.activeElement)) return
|
||||||
|
e.stopPropagation()
|
||||||
|
onCloseRef.current()
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('keydown', handleKeyDown)
|
||||||
|
return () => document.removeEventListener('keydown', handleKeyDown)
|
||||||
|
}, [isActive, containerRef])
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user