UNPKG

igniteui-webcomponents

Version:

Ignite UI for Web Components is a complete library of UI components, giving you the ability to build modern web applications using encapsulation and the concept of reusable components in a dependency-free approach.

112 lines 3.82 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; import { LitElement } from 'lit'; import { property } from 'lit/decorators.js'; import { addRootClickHandler } from '../controllers/root-click.js'; import { iterNodes } from '../util.js'; export class IgcBaseComboBoxLikeComponent extends LitElement { constructor() { super(...arguments); this._rootClickController = addRootClickHandler(this); this.keepOpenOnSelect = false; this.keepOpenOnOutsideClick = false; this.open = false; } emitClosing() { return this.emitEvent('igcClosing', { cancelable: true }); } emitClosed() { return this.emitEvent('igcClosed'); } emitOpening() { return this.emitEvent('igcOpening', { cancelable: true }); } emitOpened() { return this.emitEvent('igcOpened'); } handleAnchorClick() { this.open ? this._hide(true) : this._show(true); } async _hide(emitEvent = false) { if (!this.open || (emitEvent && !this.emitClosing())) { return false; } this.open = false; if (emitEvent) { await this.updateComplete; this.emitClosed(); } return true; } async _show(emitEvent = false) { if (this.open || (emitEvent && !this.emitOpening())) { return false; } this.open = true; if (emitEvent) { await this.updateComplete; this.emitOpened(); } return true; } async show() { return this._show(); } async hide() { return this._hide(); } async toggle() { return this.open ? this.hide() : this.show(); } } __decorate([ property({ type: Boolean, reflect: true, attribute: 'keep-open-on-select' }) ], IgcBaseComboBoxLikeComponent.prototype, "keepOpenOnSelect", void 0); __decorate([ property({ type: Boolean, reflect: true, attribute: 'keep-open-on-outside-click', }) ], IgcBaseComboBoxLikeComponent.prototype, "keepOpenOnOutsideClick", void 0); __decorate([ property({ type: Boolean, reflect: true }) ], IgcBaseComboBoxLikeComponent.prototype, "open", void 0); export function getItems(root, tagName) { return iterNodes(root, 'SHOW_ELEMENT', (item) => item.matches(tagName)); } export function getActiveItems(root, tagName) { return iterNodes(root, 'SHOW_ELEMENT', (item) => item.matches(tagName) && !item.disabled); } export function getNextActiveItem(items, from) { const current = items.indexOf(from); for (let i = current + 1; i < items.length; i++) { if (!items[i].disabled) { return items[i]; } } return items[current]; } export function getPreviousActiveItem(items, from) { const current = items.indexOf(from); for (let i = current - 1; i >= 0; i--) { if (!items[i].disabled) { return items[i]; } } return items[current]; } export function setInitialSelectionState(items) { const lastSelected = items.filter((item) => item.selected).at(-1) ?? null; for (const item of items) { if (item !== lastSelected) { item.selected = false; } } return lastSelected; } //# sourceMappingURL=combo-box.js.map