Skip to content

Commit 8bddb82

Browse files
committed
fix(tile): Maximized and fullscreen state with internal resize values
1 parent 1276405 commit 8bddb82

File tree

2 files changed

+60
-32
lines changed

2 files changed

+60
-32
lines changed

src/components/tile-manager/tile-util.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ type TileGridPosition = {
1212
row: TilePosition;
1313
};
1414

15+
type TileResizeDimensions = { width: number | null; height: number | null };
16+
1517
export const DraggedTileAttribute = 'data-drag-ghost-tile';
1618

1719
type TileGridDimension = { count: number; entries: number[]; minSize: number };
@@ -85,6 +87,15 @@ class TileResizeState {
8587
minSize: 0,
8688
};
8789

90+
public resizedDimensions: TileResizeDimensions = {
91+
width: null,
92+
height: null,
93+
};
94+
95+
public get emptyResizeDimensions(): TileResizeDimensions {
96+
return { width: null, height: null };
97+
}
98+
8899
public get gap(): number {
89100
return this._gap;
90101
}

src/components/tile-manager/tile.ts

Lines changed: 49 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { LitElement, html, nothing } from 'lit';
2-
import { property, query, state } from 'lit/decorators.js';
2+
import {
3+
property,
4+
query,
5+
queryAssignedElements,
6+
state,
7+
} from 'lit/decorators.js';
38
import { createRef, ref } from 'lit/directives/ref.js';
49
import { styleMap } from 'lit/directives/style-map.js';
510
import { startViewTransition } from '../../animations/player.js';
@@ -23,6 +28,7 @@ import {
2328
createCounter,
2429
findElementFromEventPath,
2530
getCenterPoint,
31+
isEmpty,
2632
partNameMap,
2733
} from '../common/util.js';
2834
import IgcDividerComponent from '../divider/divider.js';
@@ -125,6 +131,14 @@ export default class IgcTileComponent extends EventEmitterMixin<
125131
private _resizeState = createTileResizeState();
126132
private _dragStack = createTileDragStack();
127133

134+
private _customAdorners = new Map<string, boolean>(
135+
Object.entries({
136+
side: false,
137+
corner: false,
138+
bottom: false,
139+
})
140+
);
141+
128142
// Tile manager context properties and helpers
129143

130144
/**
@@ -168,6 +182,12 @@ export default class IgcTileComponent extends EventEmitterMixin<
168182

169183
protected _headerRef = createRef<HTMLSlotElement>();
170184

185+
@queryAssignedElements({ slot: 'title' })
186+
private _titleElements!: HTMLElement[];
187+
188+
@queryAssignedElements({ slot: 'actions' })
189+
private _actionsElements!: HTMLElement[];
190+
171191
@query(IgcResizeContainerComponent.tagName)
172192
protected _resizeContainer?: IgcResizeContainerComponent;
173193

@@ -193,19 +213,6 @@ export default class IgcTileComponent extends EventEmitterMixin<
193213
);
194214
}
195215

196-
protected get _shouldHideHeader() {
197-
const hasTitle = this._headerRef.value
198-
?.querySelector<HTMLSlotElement>('slot[name="title"]')
199-
?.assignedNodes().length;
200-
const hasActions = this.shadowRoot
201-
?.querySelector<HTMLSlotElement>('slot[name="actions"]')
202-
?.assignedNodes().length;
203-
204-
return (
205-
!hasTitle && !hasActions && this.disableMaximize && this.disableFullscreen
206-
);
207-
}
208-
209216
/**
210217
* The unique identifier of the tile.
211218
* @attr tile-id
@@ -303,6 +310,12 @@ export default class IgcTileComponent extends EventEmitterMixin<
303310
public set maximized(value: boolean) {
304311
this._maximized = value;
305312

313+
const { width, height } = value
314+
? this._resizeState.emptyResizeDimensions
315+
: this._resizeState.resizedDimensions;
316+
317+
this._resizeContainer?.setSize(width, height);
318+
306319
if (this._tileManagerCtx) {
307320
this._tileManagerCtx.instance.requestUpdate();
308321
}
@@ -359,6 +372,12 @@ export default class IgcTileComponent extends EventEmitterMixin<
359372
this.style.viewTransitionName || `tile-transition-${this.tileId}`;
360373
}
361374

375+
protected override createRenderRoot() {
376+
const root = super.createRenderRoot();
377+
root.addEventListener('slotchange', () => this.requestUpdate());
378+
return root;
379+
}
380+
362381
private _setDragState(state = true) {
363382
this._isDragging = state;
364383
this._tileContent.style.opacity = state ? '0' : '1';
@@ -489,12 +508,13 @@ export default class IgcTileComponent extends EventEmitterMixin<
489508
this.style.setProperty('grid-column', column);
490509
});
491510

492-
await transition?.finished;
511+
await transition?.updateCallbackDone;
493512

494513
const { width, height } = this._resizeState.calculateResizedSize(
495514
this._cssContainer
496515
);
497516

517+
this._resizeState.resizedDimensions = { width, height };
498518
this._resizeContainer?.setSize(width, height);
499519
this._setResizeState(false);
500520
}
@@ -504,6 +524,11 @@ export default class IgcTileComponent extends EventEmitterMixin<
504524
}
505525

506526
private _handleFullscreen() {
527+
const { width, height } = !this.fullscreen
528+
? this._resizeState.emptyResizeDimensions
529+
: this._resizeState.resizedDimensions;
530+
531+
this._resizeContainer?.setSize(width, height);
507532
this._fullscreenController.setState(!this.fullscreen);
508533
}
509534

@@ -556,10 +581,16 @@ export default class IgcTileComponent extends EventEmitterMixin<
556581
}
557582

558583
protected _renderHeader() {
584+
const hideHeader =
585+
isEmpty(this._titleElements) &&
586+
isEmpty(this._actionsElements) &&
587+
this.disableMaximize &&
588+
this.disableFullscreen;
589+
559590
return html`
560-
<section part="header" ?hidden=${this._shouldHideHeader}>
591+
<section part="header" ?hidden=${hideHeader}>
561592
<header part="title" ${ref(this._headerRef)}>
562-
<slot name="title" @slotchange=${this.requestUpdate}></slot>
593+
<slot name="title"></slot>
563594
</header>
564595
<section id="tile-actions" part="actions">
565596
${!this.disableMaximize
@@ -573,7 +604,7 @@ export default class IgcTileComponent extends EventEmitterMixin<
573604
>`
574605
: nothing}
575606
576-
<slot name="actions" @slotchange=${this.requestUpdate}></slot>
607+
<slot name="actions"></slot>
577608
</section>
578609
</section>
579610
<igc-divider></igc-divider>
@@ -609,20 +640,6 @@ export default class IgcTileComponent extends EventEmitterMixin<
609640
`;
610641
}
611642

612-
protected override createRenderRoot() {
613-
const root = super.createRenderRoot();
614-
root.addEventListener('slotchange', () => this.requestUpdate());
615-
return root;
616-
}
617-
618-
private _customAdorners = new Map<string, boolean>(
619-
Object.entries({
620-
side: false,
621-
corner: false,
622-
bottom: false,
623-
})
624-
);
625-
626643
private _renderAdornerSlot(name: AdornerType) {
627644
return html`
628645
<slot

0 commit comments

Comments
 (0)