Browse Source

Various improvements

pull/6575/head
Thomas Kaul 1 day ago
parent
commit
31a308416b
  1. 6
      libs/ui/src/lib/value/value.component.stories.ts
  2. 15
      libs/ui/src/lib/value/value.component.ts

6
libs/ui/src/lib/value/value.component.stories.ts

@ -14,13 +14,13 @@ export default {
})
],
argTypes: {
enableCopyToClipboardButton: {
control: 'boolean'
},
deviceType: {
control: 'select',
options: ['desktop', 'mobile']
},
enableCopyToClipboardButton: {
control: 'boolean'
},
size: {
control: 'select',
options: ['small', 'medium', 'large']

15
libs/ui/src/lib/value/value.component.ts

@ -5,6 +5,7 @@ import { CommonModule } from '@angular/common';
import {
AfterViewInit,
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
computed,
CUSTOM_ELEMENTS_SCHEMA,
@ -47,7 +48,8 @@ export class GfValueComponent implements AfterViewInit, OnChanges {
@Input() unit = '';
@Input() value: number | string = '';
@ViewChild('labelContent', { static: false }) labelContent!: ElementRef;
@ViewChild('labelContent', { static: false })
labelContent!: ElementRef<HTMLSpanElement>;
public absoluteValue = 0;
public formattedValue = '';
@ -57,6 +59,7 @@ export class GfValueComponent implements AfterViewInit, OnChanges {
public useAbsoluteValue = false;
public constructor(
private changeDetectorRef: ChangeDetectorRef,
private clipboard: Clipboard,
private snackBar: MatSnackBar
) {
@ -82,8 +85,14 @@ export class GfValueComponent implements AfterViewInit, OnChanges {
}
public ngAfterViewInit() {
const el = this.labelContent.nativeElement;
this.hasLabel = el.textContent.trim().length > 0 || el.children.length > 0;
if (this.labelContent) {
const element = this.labelContent.nativeElement;
this.hasLabel =
element.children.length > 0 || element.textContent.trim().length > 0;
this.changeDetectorRef.markForCheck();
}
}
public ngOnChanges() {

Loading…
Cancel
Save