Skip to content

Commit

Permalink
fix(core): toolbar render spacer before overflow conditionally
Browse files Browse the repository at this point in the history
  • Loading branch information
droshev committed Sep 23, 2024
1 parent 08ef8f5 commit d0d28cd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
4 changes: 3 additions & 1 deletion libs/core/toolbar/toolbar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ <h4 fd-title class="fd-toolbar__title" [id]="titleId" #titleElement>{{ title }}<
}
<ng-content></ng-content>
@if (overflownItems.length > 0) {
<fd-toolbar-spacer></fd-toolbar-spacer>
@if (!spacerUsed()) {
<fd-toolbar-spacer></fd-toolbar-spacer>
}
<fd-toolbar-separator></fd-toolbar-separator>
<fd-popover placement="bottom-end" [noArrow]="true" class="fd-popover">
<fd-popover-control>
Expand Down
19 changes: 19 additions & 0 deletions libs/core/toolbar/toolbar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Component,
ContentChild,
ContentChildren,
contentChildren,
DestroyRef,
ElementRef,
forwardRef,
Expand All @@ -16,6 +17,7 @@ import {
Input,
Optional,
QueryList,
signal,
SkipSelf,
ViewChild,
ViewEncapsulation
Expand Down Expand Up @@ -178,6 +180,12 @@ export class ToolbarComponent implements AfterViewInit, AfterViewChecked, CssCla
/** @hidden */
overflownItems: ToolbarItem[] = [];

/** @hidden */
spacerUsed = signal(false);

/** @hidden */
spacerDirectives = contentChildren(ToolbarSpacerDirective);

/** HTML Element Reference. */
readonly elementRef = inject(ElementRef);

Expand Down Expand Up @@ -224,6 +232,8 @@ export class ToolbarComponent implements AfterViewInit, AfterViewChecked, CssCla

/** @hidden */
ngAfterViewInit(): void {
this._updateSpacerUsed();

this.overflowItems$ = combineLatest([
this.resizeObserverService.observe(this.elementRef.nativeElement).pipe(map(() => this._toolbarWidth)),
this.toolbarItems.changes.pipe(
Expand Down Expand Up @@ -318,6 +328,15 @@ export class ToolbarComponent implements AfterViewInit, AfterViewChecked, CssCla
this._refreshOverflow$.next();
}

/** hidden */
private _updateSpacerUsed(): void {
// do not render extra spacer if there is at least one passed by the application
// and it is not fixed this.spacerUsed.set(this.spacer.length > 0 && this.spacer.some((spacer) => !spacer.fixed));
this.spacerUsed.set(
this.spacerDirectives().length > 0 && this.spacerDirectives().some((spacer) => !spacer.fixed)
);
}

/** @hidden Get group number with the lowest priority.
* Uses for detecting a group of elements which would be hidden from the toolbar.
* */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class ToolbarSeparatorExampleComponent {}
selector: 'fd-toolbar-overflow-priority-example',
templateUrl: './toolbar-overflow-priority-example.component.html',
standalone: true,
imports: [ToolbarComponent, ButtonComponent, ToolbarItemDirective]
imports: [ToolbarComponent, ButtonComponent, ToolbarItemDirective, ToolbarSpacerDirective]
})
export class ToolbarOverflowPriorityExampleComponent {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<fd-toolbar [shouldOverflow]="true" ariaLabel="Toolbar overflow priority">
<button fd-toolbar-item fd-button label="Button First"></button>
<button fd-toolbar-item fd-button label="Always" fdOverflowPriority="always"></button>
<fd-toolbar-spacer [fixed]="true" style="width: 50px"></fd-toolbar-spacer>
<button fd-toolbar-item fd-button label="Never" fdOverflowPriority="never"></button>
<button fd-toolbar-item fd-button label="Low" fdOverflowPriority="low"></button>
<fd-toolbar-spacer></fd-toolbar-spacer>
<button fd-toolbar-item fd-button label="High" fdOverflowPriority="high"></button>
<button fd-toolbar-item fd-button label="Disappear" fdOverflowPriority="disappear"></button>
<button fd-toolbar-item fd-button label="Button Last"></button>
Expand Down

0 comments on commit d0d28cd

Please sign in to comment.