1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-12 14:34:02 +00:00

[CL-498] Set chip menu width minimum to chip select width (#11905)

This commit is contained in:
Victoria League
2024-11-08 15:57:52 -05:00
committed by GitHub
parent 5bebba33c8
commit 7e09088ab0
2 changed files with 10 additions and 2 deletions

View File

@@ -24,6 +24,7 @@
[title]="label"
#menuTrigger="menuTrigger"
(click)="setMenuWidth()"
#chipSelectButton
>
<span class="tw-inline-flex tw-items-center tw-gap-1.5 tw-truncate">
<i class="bwi !tw-text-[inherit]" [ngClass]="icon"></i>

View File

@@ -2,6 +2,7 @@ import {
AfterViewInit,
Component,
DestroyRef,
ElementRef,
HostBinding,
HostListener,
Input,
@@ -45,6 +46,7 @@ export type ChipSelectOption<T> = Option<T> & {
export class ChipSelectComponent<T = unknown> implements ControlValueAccessor, AfterViewInit {
@ViewChild(MenuComponent) menu: MenuComponent;
@ViewChildren(MenuItemDirective) menuItems: QueryList<MenuItemDirective>;
@ViewChild("chipSelectButton") chipSelectButton: ElementRef<HTMLButtonElement>;
/** Text to show when there is no selected option */
@Input({ required: true }) placeholderText: string;
@@ -210,11 +212,16 @@ export class ChipSelectComponent<T = unknown> implements ControlValueAccessor, A
}
/**
* Calculate the width of the menu according to the initially rendered options
* Calculate the width of the menu based on whichever is larger, the chip select width or the width of
* the initially rendered options
*/
protected setMenuWidth() {
this.menuWidth =
const chipWidth = this.chipSelectButton.nativeElement.getBoundingClientRect().width;
const firstMenuItemWidth =
this.menu.menuItems.first.elementRef.nativeElement.getBoundingClientRect().width;
this.menuWidth = Math.max(chipWidth, firstMenuItemWidth);
}
/** Control Value Accessor */