From 3a734867a276d77f019004cc02723cf1c9273bcb Mon Sep 17 00:00:00 2001 From: basher Date: Tue, 2 Apr 2024 16:46:59 +0100 Subject: [PATCH] fix disclosure focus --- ui/npm-shrinkwrap.json | 4 ++-- .../javascript/web-components/webui-disclosure.ts | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/ui/npm-shrinkwrap.json b/ui/npm-shrinkwrap.json index 2f23270..91209d8 100644 --- a/ui/npm-shrinkwrap.json +++ b/ui/npm-shrinkwrap.json @@ -1,12 +1,12 @@ { "name": "web-ui-boilerplate", - "version": "2.1.3", + "version": "2.1.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "web-ui-boilerplate", - "version": "2.1.3", + "version": "2.1.4", "license": "ISC", "dependencies": { "dialog-polyfill": "^0.5.6" diff --git a/ui/src/javascript/web-components/webui-disclosure.ts b/ui/src/javascript/web-components/webui-disclosure.ts index 622c566..70f3d10 100644 --- a/ui/src/javascript/web-components/webui-disclosure.ts +++ b/ui/src/javascript/web-components/webui-disclosure.ts @@ -47,18 +47,21 @@ export default class WebUIDisclosure extends HTMLElement { return random; } - private hideContent(): void { + private hideContent(e?: KeyboardEvent): void { if (this.trigger?.getAttribute('aria-expanded') === 'true') { - // Set keyboard :FOCUS on the trigger button. - this.trigger?.focus(); this.trigger?.setAttribute('aria-expanded', 'false'); + this.content?.setAttribute('hidden', ''); + + // Set keyboard :FOCUS on the trigger button. + if (e?.type === 'keyup') { + this.trigger?.focus(); + } } - this.content?.setAttribute('hidden', ''); } private handleGlobalKeyup(e: KeyboardEvent): void { if (this.bindEscapeKey && e.code === 'Escape') { - this.hideContent(); + this.hideContent(e); } }