carbon-custom-elements
Version:
A Carbon Design System variant that's as easy to use as native HTML elements, with no framework tax, no framework silo.
1 lines • 1.54 kB
Source Map (JSON)
{"version":3,"sources":["globals/mixins/focus.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH;;;GAGG;AACH,QAAA,MAAM,UAAU;;QAEZ;;WAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAcJ,CAAC;AAEJ,eAAe,UAAU,CAAC","file":"focus.d.ts","sourcesContent":["/**\n * @license\n *\n * Copyright IBM Corp. 2019\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport { selectorTabbable } from '../settings';\n\n/**\n * @param Base The base class.\n * @returns A mix-in implementing `.focus()` method that focuses on the first focusable element in the shadow DOM.\n */\nconst FocusMixin = <T extends Constructor<HTMLElement>>(Base: T) =>\n class extends Base {\n /**\n * Focuses on the first focusable element in the shadow DOM.\n */\n focus() {\n // @ts-ignore: Until `delegatesFocus` is added to `ShadowRoot` definition\n if (this.shadowRoot!.delegatesFocus) {\n super.focus();\n } else {\n const delegateTarget = this.shadowRoot!.querySelector(selectorTabbable) || this.querySelector(selectorTabbable);\n if (delegateTarget) {\n (delegateTarget as HTMLElement).focus();\n } else {\n super.focus();\n }\n }\n }\n };\n\nexport default FocusMixin;\n"]}