From 3de1ebf74974ec69f45e0f67e9c1df41659a18c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tu=C4=9F=C3=A7e=20K=C3=BC=C3=A7=C3=BCko=C4=9Flu?= Date: Tue, 15 Nov 2022 16:26:23 +0300 Subject: [PATCH] Refactor #3233 --- src/components/sidebar/Sidebar.vue | 34 ++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/components/sidebar/Sidebar.vue b/src/components/sidebar/Sidebar.vue index 2f500716c4..31a33c0cdb 100755 --- a/src/components/sidebar/Sidebar.vue +++ b/src/components/sidebar/Sidebar.vue @@ -2,15 +2,15 @@
-
+
-
-
+
@@ -65,6 +65,9 @@ export default { mask: null, maskClickListener: null, container: null, + content: null, + headerContainer: null, + closeButton: null, beforeUnmount() { this.destroyModal(); @@ -104,11 +107,21 @@ export default { } }, focus() { - let focusable = DomHandler.findSingle(this.container, 'input,button'); + const findFocusableElement = (container) => { + return container.querySelector('[autofocus]'); + }; - if (focusable) { - focusable.focus(); + let focusTarget = this.$slots.default && findFocusableElement(this.content); + + if (!focusTarget) { + focusTarget = this.$slots.header && findFocusableElement(this.headerContainer); + + if (!focusTarget) { + focusTarget = this.showCloseIcon ? this.closeButton : null; + } } + + focusTarget && focusTarget.focus(); }, enableModality() { if (!this.mask) { @@ -162,6 +175,15 @@ export default { }, containerRef(el) { this.container = el; + }, + contentRef(el) { + this.content = el; + }, + headerContainerRef(el) { + this.headerContainer = el; + }, + closeButtonRef(el) { + this.closeButton = el; } }, computed: {