PluginProbe
Gutenberg / 23.7.2
Gutenberg v23.7.2
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / build / modules / block-library / search / view.js

view.js in Gutenberg 23.7.2, at build/modules/block-library/search/view.js

65 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 // packages/block-library/build-module/search/view.mjs
2 import {
3 store,
4 getContext,
5 getElement,
6 withSyncEvent
7 } from "@wordpress/interactivity";
8 var { actions } = store(
9 "core/search",
10 {
11 state: {
12 get ariaLabel() {
13 const {
14 isSearchInputVisible,
15 ariaLabelCollapsed,
16 ariaLabelExpanded
17 } = getContext();
18 return isSearchInputVisible ? ariaLabelExpanded : ariaLabelCollapsed;
19 },
20 get ariaControls() {
21 const { isSearchInputVisible, inputId } = getContext();
22 return isSearchInputVisible ? null : inputId;
23 },
24 get type() {
25 const { isSearchInputVisible } = getContext();
26 return isSearchInputVisible ? "submit" : "button";
27 },
28 get tabindex() {
29 const { isSearchInputVisible } = getContext();
30 return isSearchInputVisible ? "0" : "-1";
31 }
32 },
33 actions: {
34 openSearchInput: withSyncEvent((event) => {
35 const ctx = getContext();
36 const { ref } = getElement();
37 if (!ctx.isSearchInputVisible) {
38 event.preventDefault();
39 ctx.isSearchInputVisible = true;
40 ref.parentElement.querySelector("input").focus();
41 }
42 }),
43 closeSearchInput() {
44 const ctx = getContext();
45 ctx.isSearchInputVisible = false;
46 },
47 handleSearchKeydown: withSyncEvent((event) => {
48 const { ref } = getElement();
49 if (event?.key === "Escape") {
50 actions.closeSearchInput();
51 ref.querySelector("button").focus();
52 }
53 }),
54 handleSearchFocusout: withSyncEvent((event) => {
55 const { ref } = getElement();
56 if (!ref.contains(event.relatedTarget) && event.target !== window.document.activeElement) {
57 actions.closeSearchInput();
58 }
59 })
60 }
61 },
62 { lock: true }
63 );
64 //# sourceMappingURL=view.js.map
65