Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(select): "show more" text calculations (#DS-2649) #135

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions packages/components/select/select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ import {
distinctUntilChanged,
delay
} from 'rxjs/operators';
import { SizeXxs } from '@koobiq/design-tokens';


let nextUniqueId = 0;
Expand Down Expand Up @@ -230,6 +231,9 @@ export class KbqSelect extends KbqSelectMixinBase implements
}
];

/**
* Trigger - is a clickable field to open select dropdown panel
*/
@ViewChild('trigger', { static: false }) trigger: ElementRef;

@ViewChild('panel', { static: false }) panel: ElementRef;
Expand Down Expand Up @@ -944,12 +948,13 @@ export class KbqSelect extends KbqSelectMixinBase implements
this._renderer.appendChild(this.trigger.nativeElement, triggerClone);

let totalItemsWidth: number = 0;
(triggerClone.querySelectorAll('kbq-tag') as NodeListOf<HTMLElement>)
.forEach((item) => totalItemsWidth += this.getItemWidth(item));
const selectedItemsViewValueContainers = triggerClone.querySelectorAll<HTMLElement>('kbq-tag');
selectedItemsViewValueContainers.forEach((item) => totalItemsWidth += this.getItemWidth(item));

triggerClone.remove();

return totalItemsWidth;
// item width + flex gap between each item
return totalItemsWidth + parseInt(SizeXxs) * (selectedItemsViewValueContainers.length - 1);
}

private getItemWidth(element: HTMLElement): number {
Expand Down
12 changes: 9 additions & 3 deletions packages/components/tree-select/tree-select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ import {
startWith,
delay
} from 'rxjs/operators';
import { SizeXxs } from '@koobiq/design-tokens';


let nextUniqueId = 0;
Expand Down Expand Up @@ -221,6 +222,10 @@ export class KbqTreeSelect extends KbqTreeSelectMixinBase implements

options: QueryList<KbqTreeOption>;


/**
* Trigger - is a clickable field to open select dropdown panel
*/
@ViewChild('trigger', { static: false }) trigger: ElementRef;

@ViewChild('panel', { static: false }) panel: ElementRef;
Expand Down Expand Up @@ -896,12 +901,13 @@ export class KbqTreeSelect extends KbqTreeSelectMixinBase implements
this.renderer.appendChild(this.trigger.nativeElement, triggerClone);

let totalItemsWidth: number = 0;
(triggerClone.querySelectorAll('kbq-tag') as NodeListOf<HTMLElement>)
.forEach((item) => totalItemsWidth += this.getItemWidth(item));
const selectedItemsViewValueContainers = triggerClone.querySelectorAll<HTMLElement>('kbq-tag');
selectedItemsViewValueContainers.forEach((item) => totalItemsWidth += this.getItemWidth(item));

triggerClone.remove();

return totalItemsWidth;
// item width + flex gap between each item
return totalItemsWidth + parseInt(SizeXxs) * (selectedItemsViewValueContainers.length - 1);
}

private getTotalVisibleItems(): [number, number] {
Expand Down
1 change: 0 additions & 1 deletion tools/public_api_guard/components/select.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ export class KbqSelect extends KbqSelectMixinBase implements AfterContentInit, A
tags: QueryList<KbqTag>;
toggle(): void;
transformOrigin: string;
// (undocumented)
trigger: ElementRef;
triggerFontSize: number;
triggerRect: ClientRect;
Expand Down
1 change: 0 additions & 1 deletion tools/public_api_guard/components/tree-select.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ export class KbqTreeSelect extends KbqTreeSelectMixinBase implements AfterConten
transformOrigin: string;
// (undocumented)
tree: KbqTreeSelection;
// (undocumented)
trigger: ElementRef;
triggerFontSize: number;
triggerRect: DOMRect;
Expand Down