@sandlada/mdc
Version:
@sandlada/mdc is an open source component library that follows the Material Design 3 design specifications.
10 lines (9 loc) • 1.3 kB
JavaScript
import"../../lit-element-Ho-VPzO1.js";
/**
* @license
* Copyright 2023 Google LLC
* SPDX-License-Identifier: Apache-2.0
*
* @link
* https://github.com/material-components/material-web/blob/main/internal/controller/attachable-controller.ts
*/const t=Symbol("attachableController");let o;o=new MutationObserver(o=>{for(const r of o)r.target[t]?.hostConnected()});class r{get htmlFor(){return this.host.getAttribute("for")}set htmlFor(t){null===t?this.host.removeAttribute("for"):this.host.setAttribute("for",t)}get control(){return this.host.hasAttribute("for")?this.htmlFor&&this.host.isConnected?this.host.getRootNode().querySelector(`#${this.htmlFor}`):null:this.currentControl||this.host.parentElement}set control(t){t?this.attach(t):this.detach()}constructor(r,e){this.currentControl=null,this.host=r,this.onControlChange=e,r.addController(this),r[t]=this,o?.observe(r,{attributeFilter:["for"]})}attach(t){t!==this.currentControl&&(this.setCurrentControl(t),this.host.removeAttribute("for"))}detach(){this.setCurrentControl(null),this.host.setAttribute("for","")}hostConnected(){this.setCurrentControl(this.control)}hostDisconnected(){this.setCurrentControl(null)}setCurrentControl(t){this.onControlChange(this.currentControl,t),this.currentControl=t}}export{r as AttachableController};