[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/blocks/search/ -> view.js (source)

   1  import * as __WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__ from "@wordpress/interactivity";
   2  /******/ // The require scope
   3  /******/ var __webpack_require__ = {};
   4  /******/ 
   5  /************************************************************************/
   6  /******/ /* webpack/runtime/define property getters */
   7  /******/ (() => {
   8  /******/     // define getter functions for harmony exports
   9  /******/     __webpack_require__.d = (exports, definition) => {
  10  /******/         for(var key in definition) {
  11  /******/             if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  12  /******/                 Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  13  /******/             }
  14  /******/         }
  15  /******/     };
  16  /******/ })();
  17  /******/ 
  18  /******/ /* webpack/runtime/hasOwnProperty shorthand */
  19  /******/ (() => {
  20  /******/     __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
  21  /******/ })();
  22  /******/ 
  23  /************************************************************************/
  24  var __webpack_exports__ = {};
  25  
  26  ;// external "@wordpress/interactivity"
  27  var x = (y) => {
  28      var x = {}; __webpack_require__.d(x, y); return x
  29  } 
  30  var y = (x) => (() => (x))
  31  const interactivity_namespaceObject = x({ ["getContext"]: () => (__WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__.getContext), ["getElement"]: () => (__WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__.getElement), ["store"]: () => (__WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__.store), ["withSyncEvent"]: () => (__WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__.withSyncEvent) });
  32  ;// ./node_modules/@wordpress/block-library/build-module/search/view.js
  33  
  34  const { actions } = (0,interactivity_namespaceObject.store)(
  35    "core/search",
  36    {
  37      state: {
  38        get ariaLabel() {
  39          const {
  40            isSearchInputVisible,
  41            ariaLabelCollapsed,
  42            ariaLabelExpanded
  43          } = (0,interactivity_namespaceObject.getContext)();
  44          return isSearchInputVisible ? ariaLabelExpanded : ariaLabelCollapsed;
  45        },
  46        get ariaControls() {
  47          const { isSearchInputVisible, inputId } = (0,interactivity_namespaceObject.getContext)();
  48          return isSearchInputVisible ? null : inputId;
  49        },
  50        get type() {
  51          const { isSearchInputVisible } = (0,interactivity_namespaceObject.getContext)();
  52          return isSearchInputVisible ? "submit" : "button";
  53        },
  54        get tabindex() {
  55          const { isSearchInputVisible } = (0,interactivity_namespaceObject.getContext)();
  56          return isSearchInputVisible ? "0" : "-1";
  57        }
  58      },
  59      actions: {
  60        openSearchInput: (0,interactivity_namespaceObject.withSyncEvent)((event) => {
  61          const ctx = (0,interactivity_namespaceObject.getContext)();
  62          const { ref } = (0,interactivity_namespaceObject.getElement)();
  63          if (!ctx.isSearchInputVisible) {
  64            event.preventDefault();
  65            ctx.isSearchInputVisible = true;
  66            ref.parentElement.querySelector("input").focus();
  67          }
  68        }),
  69        closeSearchInput() {
  70          const ctx = (0,interactivity_namespaceObject.getContext)();
  71          ctx.isSearchInputVisible = false;
  72        },
  73        handleSearchKeydown(event) {
  74          const { ref } = (0,interactivity_namespaceObject.getElement)();
  75          if (event?.key === "Escape") {
  76            actions.closeSearchInput();
  77            ref.querySelector("button").focus();
  78          }
  79        },
  80        handleSearchFocusout(event) {
  81          const { ref } = (0,interactivity_namespaceObject.getElement)();
  82          if (!ref.contains(event.relatedTarget) && event.target !== window.document.activeElement) {
  83            actions.closeSearchInput();
  84          }
  85        }
  86      }
  87    },
  88    { lock: true }
  89  );
  90  


Generated : Thu Oct 23 08:20:05 2025 Cross-referenced by PHPXref