Skip to content

Commit

Permalink
Make scenario name input resize to fit content
Browse files Browse the repository at this point in the history
  • Loading branch information
jmccollum-woolpert committed Mar 26, 2024
1 parent cc797c6 commit 59d6f78
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<div class="d-flex flex-row align-items-center ml-3">
<mat-icon class="blue-svg-icon mb-1" svgIcon="dataset"></mat-icon>
<input
matInput
class="mat-h3 m-0 ml-1 scenario-input"
placeholder="Scenario name"
(input)="onSave()"
[(ngModel)]="scenarioName"
#scenarioInput />
<div class="resizable-input-container">
<span class="resize-text mat-h3 m-0" #resizeText>span</span>
<input
matInput
class="scenario-input mat-h3 m-0"
placeholder="Scenario name"
(input)="onSave()"
[(ngModel)]="scenarioName"
#scenarioInput />
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
@import '../../../../styles/variables.scss';

.scenario-input {
.resizable-input-container {
display: inline-block;
position: relative;
max-width: 50vw;
min-width: 14em;
min-height: 3em;
}

.resize-text {
display: inline-block;
visibility: hidden;
white-space: pre;
padding: 0.25em 0.5em;
}

.scenario-input {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
border-width: 2px;
border-style: inset;
border-color: transparent;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core';
import {
AfterViewInit,
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
ElementRef,
ViewChild,
} from '@angular/core';
import { Store } from '@ngrx/store';
import { selectScenarioName } from '../../selectors/dispatcher.selectors';
import { saveScenarioName } from '../../actions/dispatcher.actions';
Expand All @@ -9,18 +16,26 @@ import { saveScenarioName } from '../../actions/dispatcher.actions';
styleUrls: ['./dataset.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class DatasetComponent implements OnInit {
export class DatasetComponent implements AfterViewInit {
@ViewChild('scenarioInput') scenarioInput: ElementRef;
@ViewChild('resizeText') resizeText: ElementRef;
scenarioName: string;

constructor(private store: Store, private detectRef: ChangeDetectorRef) {}

ngOnInit(): void {
ngAfterViewInit(): void {
this.store.select(selectScenarioName).subscribe((value) => {
this.scenarioName = value;
this.updateInputSize();
this.detectRef.markForCheck();
});
}

updateInputSize(): void {
// this.scenarioInput.nativeElement.size = this.scenarioName.length || 1;
this.resizeText.nativeElement.textContent = this.scenarioName;
}

onSave(): void {
this.store.dispatch(saveScenarioName({ scenarioName: this.scenarioName }));
}
Expand Down

0 comments on commit 59d6f78

Please sign in to comment.