@md-plugins/search-ui 2.0.2 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +23 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -84,6 +84,7 @@ declare class MdSearchElement extends HTMLElementBase {
|
|
|
84
84
|
private searchRequestId;
|
|
85
85
|
private selectionStart;
|
|
86
86
|
private selectionEnd;
|
|
87
|
+
private previouslyFocusedElement;
|
|
87
88
|
connectedCallback(): void;
|
|
88
89
|
disconnectedCallback(): void;
|
|
89
90
|
attributeChangedCallback(name: string): void;
|
package/dist/index.d.ts
CHANGED
|
@@ -84,6 +84,7 @@ declare class MdSearchElement extends HTMLElementBase {
|
|
|
84
84
|
private searchRequestId;
|
|
85
85
|
private selectionStart;
|
|
86
86
|
private selectionEnd;
|
|
87
|
+
private previouslyFocusedElement;
|
|
87
88
|
connectedCallback(): void;
|
|
88
89
|
disconnectedCallback(): void;
|
|
89
90
|
attributeChangedCallback(name: string): void;
|
package/dist/index.mjs
CHANGED
|
@@ -558,6 +558,7 @@ var MdSearchElement = class extends HTMLElementBase {
|
|
|
558
558
|
searchRequestId = 0;
|
|
559
559
|
selectionStart = null;
|
|
560
560
|
selectionEnd = null;
|
|
561
|
+
previouslyFocusedElement = null;
|
|
561
562
|
connectedCallback() {
|
|
562
563
|
this.render();
|
|
563
564
|
globalThis.addEventListener?.("keydown", this.onGlobalKeydown);
|
|
@@ -575,6 +576,7 @@ var MdSearchElement = class extends HTMLElementBase {
|
|
|
575
576
|
this.render();
|
|
576
577
|
}
|
|
577
578
|
open() {
|
|
579
|
+
this.previouslyFocusedElement = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
578
580
|
this.opened = true;
|
|
579
581
|
this.render();
|
|
580
582
|
this.focusInput();
|
|
@@ -582,6 +584,8 @@ var MdSearchElement = class extends HTMLElementBase {
|
|
|
582
584
|
close() {
|
|
583
585
|
this.opened = false;
|
|
584
586
|
this.render();
|
|
587
|
+
(this.previouslyFocusedElement ?? this.root.querySelector("[part=\"trigger\"]"))?.focus();
|
|
588
|
+
this.previouslyFocusedElement = null;
|
|
585
589
|
}
|
|
586
590
|
toggle() {
|
|
587
591
|
if (this.opened) this.close();
|
|
@@ -656,6 +660,21 @@ var MdSearchElement = class extends HTMLElementBase {
|
|
|
656
660
|
this.close();
|
|
657
661
|
return;
|
|
658
662
|
}
|
|
663
|
+
if (event.key === "Tab") {
|
|
664
|
+
const focusableElements = Array.from(this.root.querySelectorAll("[part=\"dialog\"] button:not([disabled]), [part=\"dialog\"] input:not([disabled])"));
|
|
665
|
+
const firstElement = focusableElements[0];
|
|
666
|
+
const lastElement = focusableElements.at(-1);
|
|
667
|
+
if (firstElement !== void 0 && lastElement !== void 0) {
|
|
668
|
+
if (event.shiftKey && this.root.activeElement === firstElement) {
|
|
669
|
+
event.preventDefault();
|
|
670
|
+
lastElement.focus();
|
|
671
|
+
} else if (event.shiftKey === false && this.root.activeElement === lastElement) {
|
|
672
|
+
event.preventDefault();
|
|
673
|
+
firstElement.focus();
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
return;
|
|
677
|
+
}
|
|
659
678
|
if (event.key === "ArrowDown") {
|
|
660
679
|
event.preventDefault();
|
|
661
680
|
this.setActiveIndex(this.activeIndex + 1, { scrollIntoView: true });
|
|
@@ -710,8 +729,10 @@ var MdSearchElement = class extends HTMLElementBase {
|
|
|
710
729
|
input.setAttribute("aria-expanded", this.results.length > 0 ? "true" : "false");
|
|
711
730
|
if (this.results.length === 0) {
|
|
712
731
|
input.removeAttribute("aria-activedescendant");
|
|
732
|
+
input.removeAttribute("aria-controls");
|
|
713
733
|
return;
|
|
714
734
|
}
|
|
735
|
+
input.setAttribute("aria-controls", `${this.elementId}-listbox`);
|
|
715
736
|
input.setAttribute("aria-activedescendant", `${this.elementId}-result-${this.activeIndex}`);
|
|
716
737
|
}
|
|
717
738
|
syncActiveResult(options = {}) {
|
|
@@ -772,6 +793,7 @@ var MdSearchElement = class extends HTMLElementBase {
|
|
|
772
793
|
class="result ${index === this.activeIndex ? "result--active" : ""}"
|
|
773
794
|
data-result-index="${index}"
|
|
774
795
|
role="option"
|
|
796
|
+
tabindex="-1"
|
|
775
797
|
aria-selected="${index === this.activeIndex ? "true" : "false"}"
|
|
776
798
|
>
|
|
777
799
|
<div part="result-title" class="result__header">
|
|
@@ -830,7 +852,7 @@ var MdSearchElement = class extends HTMLElementBase {
|
|
|
830
852
|
aria-label="${escapeHtml(this.searchLabel)}"
|
|
831
853
|
aria-autocomplete="list"
|
|
832
854
|
aria-expanded="${this.results.length > 0 ? "true" : "false"}"
|
|
833
|
-
aria-controls="${this.elementId}-listbox"
|
|
855
|
+
${this.results.length > 0 ? `aria-controls="${this.elementId}-listbox"` : ""}
|
|
834
856
|
${activeResultId !== void 0 ? `aria-activedescendant="${activeResultId}"` : ""}
|
|
835
857
|
autocomplete="off"
|
|
836
858
|
spellcheck="false"
|