Skip to content

Commit

Permalink
fix: empty line when one row filled by tag and optimize #ACP-2796
Browse files Browse the repository at this point in the history
  • Loading branch information
Guodong Zang committed Jul 1, 2020
1 parent 8da8d4d commit 4f7d687
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/input/tags-input/mixin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
width: 0;
padding: 0;
margin: 0;
position: absolute;
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/select/multi-select/multi-select.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
(keydown)="onKeyDown($event)"
(input)="onInput($event)"
/>
<span #inputValueMirror [class]="bem.element('mirror')">
{{ inputValue }}
</span>
</div>

<ng-template #templateRef>
Expand Down
34 changes: 27 additions & 7 deletions src/select/multi-select/multi-select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ export class MultiSelectComponent extends BaseSelect<unknown[]>
@ViewChild('inputRef', { static: true })
inputRef: ElementRef<HTMLInputElement>;

@ViewChild('inputValueMirror', { static: true })
inputValueMirror: ElementRef<HTMLElement>;

inputValue = '';

get rootClass() {
const size = this.size || ComponentSize.Medium;
return `aui-input ${this.bem.block(size)} ${
Expand Down Expand Up @@ -168,13 +173,7 @@ export class MultiSelectComponent extends BaseSelect<unknown[]>

onInput(event: Event) {
super.onInput(event);
// TODO: optimize performance
this.renderer.removeStyle(this.inputRef.nativeElement, 'width');
this.renderer.setStyle(
this.inputRef.nativeElement,
'width',
this.inputRef.nativeElement.scrollWidth + 'px',
);
this.setInputWidth();
this.tooltipRef.updatePosition();
}

Expand Down Expand Up @@ -266,6 +265,27 @@ export class MultiSelectComponent extends BaseSelect<unknown[]>

private resetInput() {
this.inputRef.nativeElement.value = '';
this.setInputWidth();
this.filterString = '';
}

// calculate input element width according to its value
private setInputWidth() {
const { value } = this.inputRef.nativeElement;
if (!value.length) {
this.inputValue = '';
requestAnimationFrame(() => {
this.renderer.removeStyle(this.inputRef.nativeElement, 'width');
});
} else {
this.inputValue = value;
requestAnimationFrame(() => {
this.renderer.setStyle(
this.inputRef.nativeElement,
'width',
`${this.inputValueMirror.nativeElement.scrollWidth}px`,
);
});
}
}
}

0 comments on commit 4f7d687

Please sign in to comment.