MCPcopy Create free account
hub / github.com/angular/components / shouldLabelFloat

Method shouldLabelFloat

src/material/input/input.ts:524–543  ·  view source on GitHub ↗

* Implemented as part of MatFormFieldControl. * @docs-private

()

Source from the content-addressed store, hash-verified

522 * @docs-private
523 */
524 get shouldLabelFloat(): boolean {
525 if (this._isNativeSelect) {
526 // For a single-selection `<select>`, the label should float when the selected option has
527 // a non-empty display value. For a `<select multiple>`, the label *always* floats to avoid
528 // overlapping the label with the options.
529 const selectElement = this._elementRef.nativeElement as HTMLSelectElement;
530 const firstOption: HTMLOptionElement | undefined = selectElement.options[0];
531
532 // On most browsers the `selectedIndex` will always be 0, however on IE and Edge it'll be
533 // -1 if the `value` is set to something, that isn't in the list of options, at a later point.
534 return (
535 this.focused ||
536 selectElement.multiple ||
537 !this.empty ||
538 !!(selectElement.selectedIndex > -1 && firstOption && firstOption.label)
539 );
540 } else {
541 return (this.focused && !this.disabled) || !this.empty;
542 }
543 }
544
545 /**
546 * Implemented as part of MatFormFieldControl.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected