Skip to content

Commit

Permalink
Handle esc key in settings (#4702)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicodh authored Feb 25, 2025
1 parent eb3c18e commit f979e9f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- constrain size of webxdc window by available screen-workarea-space #4683
- fix that in html email view links without schema didn't open in browser #4690
- fix clicking on the same anchor multiple timed disn't work in html email view #4690
- close second level settings form with Escape key #4128

<a id="1_54_1"></a>

Expand Down
15 changes: 15 additions & 0 deletions packages/frontend/src/components/Settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ export default function Settings({ onClose }: DialogProps) {
const tx = useTranslationFunction()
const [settingsMode, setSettingsMode] = useState<SettingsView>('main')

useEffect(() => {
const handler = (evt: KeyboardEvent) => {
if (
settingsMode !== 'main' &&
window.__settingsOpened &&
evt.key === 'Escape'
) {
evt.preventDefault()
setSettingsMode('main')
}
}
document.addEventListener('keydown', handler)
return () => document.removeEventListener('keydown', handler)
}, [settingsMode])

useEffect(() => {
if (window.__settingsOpened) {
throw new Error(
Expand Down

0 comments on commit f979e9f

Please sign in to comment.