Skip to content

Commit ee365a3

Browse files
Koladata Teamcopybara-github
authored andcommitted
Compact mode for multi-dim-nav, which saves space when enabled
PiperOrigin-RevId: 856369513 Change-Id: I39d316f1517967183db41e5903ef0f02dae3a319
1 parent 05f28a7 commit ee365a3

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

ts/multi_dim_nav.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,9 @@ export interface ChangeCurrentDetail {
235235
*
236236
* Additional attributes:
237237
* - data-layout: If this is set to 'small', flags for current and cursor
238-
* positions will be smaller.
238+
* positions will be smaller.
239+
* - compact: If this is set, the data-row-height is interpreted as the total
240+
* height instead of the height of a single dimension.
239241
*/
240242
export class MultiDimNav extends NanoElement {
241243
// Element that creates all space necessary for items. Flags and slotted
@@ -319,7 +321,7 @@ export class MultiDimNav extends NanoElement {
319321
}
320322

321323
static get observedAttributes() {
322-
return ['data-sizes', 'data-layout'];
324+
return ['data-sizes', 'data-layout', 'compact'];
323325
}
324326

325327
get numDims() {
@@ -331,7 +333,11 @@ export class MultiDimNav extends NanoElement {
331333
}
332334

333335
get rowHeight() {
334-
return Number(this.dataset['rowHeight'] ?? 30);
336+
const rowHeight = Number(this.dataset['rowHeight'] ?? 30);
337+
if (this.hasAttribute('compact')) {
338+
return rowHeight / (this.node.depth + 1);
339+
}
340+
return rowHeight;
335341
}
336342

337343
/**
@@ -365,6 +371,7 @@ export class MultiDimNav extends NanoElement {
365371
);
366372
this.currentFlag = html.tag('kd-multi-index-flag', flagClasses);
367373
this.cursorFlag = html.tag('kd-multi-index-flag', flagClasses);
374+
this.syncCompact();
368375

369376
this.currentFlag.setAttribute('current', '');
370377
this.cursorFlag.setAttribute('cursor', '');
@@ -423,6 +430,17 @@ export class MultiDimNav extends NanoElement {
423430
this.render();
424431
}
425432

433+
private syncCompact() {
434+
const compact = this.hasAttribute('compact');
435+
if (compact) {
436+
this.currentFlag?.setAttribute('compact', '');
437+
this.cursorFlag?.setAttribute('compact', '');
438+
} else {
439+
this.currentFlag?.removeAttribute('compact');
440+
this.cursorFlag?.removeAttribute('compact');
441+
}
442+
}
443+
426444
private repositionSlottedElement(target: HTMLElement) {
427445
target.style.setProperty('top', '0');
428446
const begin = Number(target.dataset['begin']) || 0;
@@ -492,6 +510,8 @@ export class MultiDimNav extends NanoElement {
492510
0,
493511
);
494512
super.attributeChangedCallback(name, oldValue, newValue);
513+
} else if (name === 'compact') {
514+
this.syncCompact();
495515
}
496516
}
497517

ts/multi_index_flag.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,13 @@ export class MultiIndexFlag extends NanoElement {
4949
}
5050

5151
static get observedAttributes() {
52-
return ['data-index'];
52+
return ['data-index', 'compact'];
5353
}
5454

5555
get index(): string[] {
56+
if (this.hasAttribute('compact')) {
57+
return [this.dataset['index'] ?? ''];
58+
}
5659
return this.dataset['index']?.split(',') ?? [];
5760
}
5861

0 commit comments

Comments
 (0)