/
githubmirror
/
components
Обзор
Документация
Войти
/
githubmirror
/
components
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/material/chips/chip-edit-input.ts
54 строки
1 KB
Kristiyan Kostadinov
fix(multiple): remove empty constructors (#33048)
08 апр 2026, 22:21
Не верифицирован
08 апр 2026, 22:21
ce4c2c0
Код
Авторство
О чём код?
/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.dev/license */ import {Directive, ElementRef, inject, DOCUMENT} from '@angular/core'; /** * A directive that makes a span editable and exposes functions to modify and retrieve the * element's contents. */ @Directive({ selector: 'span[matChipEditInput]', host: { 'class': 'mat-chip-edit-input', 'role': 'textbox', 'tabindex': '-1', 'contenteditable': 'true', }, }) export class MatChipEditInput { private readonly _elementRef = inject(ElementRef); private readonly _document = inject(DOCUMENT); initialize(initialValue: string) { this.getNativeElement().focus(); this.setValue(initialValue); } getNativeElement(): HTMLElement { return this._elementRef.nativeElement; } setValue(value: string) { this.getNativeElement().textContent = value; this._moveCursorToEndOfInput(); } getValue(): string { return this.getNativeElement().textContent || ''; } private _moveCursorToEndOfInput() { const range = this._document.createRange(); range.selectNodeContents(this.getNativeElement()); range.collapse(false); const sel = window.getSelection()!; sel.removeAllRanges(); sel.addRange(range); } }