/* * Copyright (C) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { BaseElement } from '../BaseElement'; import '../icon/LitIcon'; const initHtmlStyle: string = ` `; export class LitSelectOption extends BaseElement { static get observedAttributes(): string[] { return ['selected', 'disabled', 'check']; } initHtml(): string { return ` ${initHtmlStyle}
`; } initElements(): void {} //当 custom element首次被插入文档DOM时,被调用。 connectedCallback(): void { if (!this.hasAttribute('disabled')) { this.onclick = (ev): void => { this.dispatchEvent( new CustomEvent('onSelected', { detail: { selected: true, value: this.getAttribute('value'), text: this.textContent, }, }) ); ev.stopPropagation(); }; } } //当 custom element从文档DOM中删除时,被调用。 disconnectedCallback(): void {} //当 custom element被移动到新的文档时,被调用。 adoptedCallback(): void {} //当 custom element增加、删除、修改自身属性时,被调用。 attributeChangedCallback(name: unknown, oldValue: unknown, newValue: unknown): void {} } if (!customElements.get('lit-select-option')) { customElements.define('lit-select-option', LitSelectOption); }