@nanahoshi/mona-ui 0.48.0 → 0.50.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/api/breadcrumb.json +1 -1
- package/docs/api/breadcrumb.md +5 -1
- package/docs/api/index.json +1 -1
- package/docs/api/tabs.json +1 -1
- package/docs/api/tabs.md +53 -6
- package/docs/breadcrumb.md +58 -4
- package/docs/manifest.json +1 -1
- package/docs/tabs.md +185 -12
- package/fesm2022/nanahoshi-mona-ui-breadcrumb.mjs +116 -32
- package/fesm2022/nanahoshi-mona-ui-tabs.mjs +653 -107
- package/llms.txt +1 -1
- package/package.json +1 -1
- package/types/nanahoshi-mona-ui-breadcrumb.d.ts +18 -4
- package/types/nanahoshi-mona-ui-tabs.d.ts +217 -16
package/docs/tabs.md
CHANGED
|
@@ -4,11 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
Entry point: `@nanahoshi/mona-ui/tabs`
|
|
6
6
|
|
|
7
|
-
**Selector:** `mona-tabs`
|
|
7
|
+
**Selector:** `mona-tabs`, `mona-tab-strip`
|
|
8
8
|
|
|
9
9
|
`TabsComponent` renders a set of `mona-tab` panels and lets the consumer switch between them by clicking a tab or navigating with the keyboard. Tabs are the right choice when each option labels an associated content panel — for example `Account | Security | Notifications`.
|
|
10
10
|
|
|
11
|
-
The tab strip is line-based: a horizontal rule separates the tab list from the content below it, and the active tab is marked by a short indicator line. The strip can be placed on any edge via the `position` input.
|
|
11
|
+
The tab strip is line-based by default: a horizontal rule separates the tab list from the content below it, and the active tab is marked by a short indicator line. The strip can be placed on any edge via the `position` input. With `look="pill"`, the active tab is raised on a rounded background instead.
|
|
12
|
+
|
|
13
|
+
`TabStripComponent` renders only the tab list, for tabs whose panels are elsewhere on the page, such as browser-style tabs in a window's titlebar.
|
|
12
14
|
|
|
13
15
|
For compact value selection that does not switch content panels — for example `List | Grid` or `Day | Week | Month` — use `SegmentedComponent` instead.
|
|
14
16
|
|
|
@@ -23,12 +25,16 @@ Tabs organizes related content into named panels and shows one panel at a time.
|
|
|
23
25
|
|
|
24
26
|
Tabs is not a routing mechanism. Switching tabs does not change the URL. To deep-link to a tab, read the route yourself and bind `selectedIndex`, or `selected` on the tab.
|
|
25
27
|
|
|
28
|
+
When the tabs sit apart from what they show, such as browser-style tabs in a window's titlebar over the page below, use `<mona-tab-strip>`. It draws only the tab list, and you render each tab's panel wherever it goes. See [Tabs whose panels are elsewhere](#tabs-whose-panels-are-elsewhere).
|
|
29
|
+
|
|
26
30
|
## Import & Quick Start
|
|
27
31
|
|
|
28
32
|
```typescript
|
|
29
33
|
import { TabComponent, TabContentTemplateDirective, TabsComponent } from "@nanahoshi/mona-ui/tabs";
|
|
30
34
|
```
|
|
31
35
|
|
|
36
|
+
For a strip whose panels you render yourself, import `TabStripComponent` instead of `TabsComponent`.
|
|
37
|
+
|
|
32
38
|
```html
|
|
33
39
|
<mona-tabs aria-label="Account">
|
|
34
40
|
<mona-tab title="Profile">
|
|
@@ -69,6 +75,8 @@ Each structural directive below is an `ng-template` placed as projected content
|
|
|
69
75
|
|
|
70
76
|
A title template renders inside the tab, whose content is presentational to assistive technology, so it can hold text and icons but not links or other controls.
|
|
71
77
|
|
|
78
|
+
`<mona-tab-strip>` takes the same `<mona-tab>` children and the same title template. It renders no panels, so it ignores a `monaTabContentTemplate`.
|
|
79
|
+
|
|
72
80
|
## Examples
|
|
73
81
|
|
|
74
82
|
### Setting the selected tab
|
|
@@ -180,6 +188,8 @@ export class TabsClosableExampleComponent {
|
|
|
180
188
|
</div>
|
|
181
189
|
```
|
|
182
190
|
|
|
191
|
+
A middle-click on a tab that can close asks to close it too, as it does on a browser's tabs. It doesn't select the tab, and it stops the middle button from starting to autoscroll the page. `tabClose` carries the click as its `originalEvent`.
|
|
192
|
+
|
|
183
193
|
Closing a tab is entirely the consumer's responsibility — see [Tabs are removed by the consumer](#tabs-are-removed-by-the-consumer).
|
|
184
194
|
|
|
185
195
|
### Reordering tabs
|
|
@@ -316,16 +326,160 @@ A left or right strip requires a constrained available height so its tabs can sc
|
|
|
316
326
|
</mona-tabs>
|
|
317
327
|
```
|
|
318
328
|
|
|
329
|
+
### The pill look
|
|
330
|
+
|
|
331
|
+
`look="pill"` rounds every tab and raises the selected one on a background with a shadow, in place of the indicator line, and drops the rule between the strip and the content. It suits a strip that stands on its own, such as one in a titlebar. `look` takes the same values on `mona-tabs` and `mona-tab-strip`, and defaults to `"line"`.
|
|
332
|
+
|
|
333
|
+
```html
|
|
334
|
+
<mona-tab-strip aria-label="Open folders" look="pill">...</mona-tab-strip>
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
The selected pill's background is `--mona-tab-pill-background` when it's set, and the theme's raised surface, `--color-surface-raised`, when it isn't. The shadow is the theme's `--shadow-raised`. A theme whose raised surface sits too close to the color behind the strip can point the property at a token of its own, on the strip or anywhere above it:
|
|
338
|
+
|
|
339
|
+
```css
|
|
340
|
+
.app-titlebar {
|
|
341
|
+
--mona-tab-pill-background: var(--color-surface-active);
|
|
342
|
+
}
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
Pills keep one font weight, so selecting a tab doesn't change its width. In forced colors, where backgrounds and shadows don't paint, the selected pill gets a ring in the system highlight color instead. When the user asks for more contrast, it gets a ring in the text color as well as its background.
|
|
346
|
+
|
|
347
|
+
### Tabs whose panels are elsewhere
|
|
348
|
+
|
|
349
|
+
`<mona-tab-strip>` renders only the tab list. Each tab's panel is yours to render, anywhere on the page, which suits browser-style tabs in a window's titlebar over the content below. It takes the same `<mona-tab>` children as `mona-tabs`, and keeps the same `selectedIndex`, `closable`, `sortable`, keyboard and scrolling behavior.
|
|
350
|
+
|
|
351
|
+
`strip-example.component.ts`
|
|
352
|
+
|
|
353
|
+
```typescript
|
|
354
|
+
import { Component, computed, signal } from "@angular/core";
|
|
355
|
+
import { LucideFolder, LucidePlus } from "@lucide/angular";
|
|
356
|
+
import { ButtonDirective } from "@nanahoshi/mona-ui/button";
|
|
357
|
+
import { moveItem } from "@nanahoshi/mona-ui/sortable";
|
|
358
|
+
import {
|
|
359
|
+
type TabCloseEvent,
|
|
360
|
+
type TabReorderEvent,
|
|
361
|
+
TabComponent,
|
|
362
|
+
TabStripComponent,
|
|
363
|
+
TabTitleTemplateDirective
|
|
364
|
+
} from "@nanahoshi/mona-ui/tabs";
|
|
365
|
+
|
|
366
|
+
interface Folder {
|
|
367
|
+
readonly id: number;
|
|
368
|
+
readonly items: number;
|
|
369
|
+
readonly name: string;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
@Component({
|
|
373
|
+
selector: "app-tabs-strip-example",
|
|
374
|
+
imports: [ButtonDirective, LucideFolder, LucidePlus, TabComponent, TabStripComponent, TabTitleTemplateDirective],
|
|
375
|
+
templateUrl: "./strip-example.component.html"
|
|
376
|
+
})
|
|
377
|
+
export class TabsStripExampleComponent {
|
|
378
|
+
#nextId = 4;
|
|
379
|
+
protected readonly folders = signal<readonly Folder[]>([
|
|
380
|
+
{ id: 1, items: 12, name: "Documents" },
|
|
381
|
+
{ id: 2, items: 48, name: "Pictures" },
|
|
382
|
+
{ id: 3, items: 7, name: "Projects" }
|
|
383
|
+
]);
|
|
384
|
+
/** The panel shows the selected folder, and the strip moves the selection when that folder's tab closes. */
|
|
385
|
+
protected readonly selected = computed(() => this.folders()[this.selectedIndex()] ?? null);
|
|
386
|
+
protected readonly selectedIndex = signal(0);
|
|
387
|
+
|
|
388
|
+
protected add(): void {
|
|
389
|
+
const id = this.#nextId++;
|
|
390
|
+
this.folders.update(folders => [...folders, { id, items: 0, name: `New folder ${id}` }]);
|
|
391
|
+
this.selectedIndex.set(this.folders().length - 1);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/** The strip only asks; removing the folder is what closes its tab. */
|
|
395
|
+
protected close(event: TabCloseEvent): void {
|
|
396
|
+
this.folders.update(folders => folders.filter((_, index) => index !== event.index));
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
protected reorder(event: TabReorderEvent): void {
|
|
400
|
+
this.folders.update(folders => moveItem(folders, event.previousIndex, event.currentIndex));
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
`strip-example.component.html`
|
|
406
|
+
|
|
407
|
+
```html
|
|
408
|
+
<div class="flex w-[32rem] max-w-full flex-col overflow-hidden rounded-lg border border-border">
|
|
409
|
+
<div class="flex h-12 items-center gap-1 bg-canvas px-2">
|
|
410
|
+
<mona-tab-strip
|
|
411
|
+
aria-label="Open folders"
|
|
412
|
+
look="pill"
|
|
413
|
+
size="small"
|
|
414
|
+
closable
|
|
415
|
+
sortable
|
|
416
|
+
[(selectedIndex)]="selectedIndex"
|
|
417
|
+
(tabClose)="close($event)"
|
|
418
|
+
(tabReorder)="reorder($event)">
|
|
419
|
+
@for (folder of folders(); track folder.id) {
|
|
420
|
+
<mona-tab [tabId]="'folder-tab-' + folder.id" panelId="folder-view" [title]="folder.name">
|
|
421
|
+
<ng-template monaTabTitleTemplate>
|
|
422
|
+
<span class="flex items-center gap-1.5">
|
|
423
|
+
<svg lucideFolder aria-hidden="true" [size]="14"></svg>
|
|
424
|
+
<span>{{ folder.name }}</span>
|
|
425
|
+
</span>
|
|
426
|
+
</ng-template>
|
|
427
|
+
</mona-tab>
|
|
428
|
+
}
|
|
429
|
+
</mona-tab-strip>
|
|
430
|
+
<button monaButton look="ghost" size="small" [iconOnly]="true" aria-label="New tab" (click)="add()">
|
|
431
|
+
<svg lucidePlus [size]="15"></svg>
|
|
432
|
+
</button>
|
|
433
|
+
<div class="h-full min-w-6 flex-1"></div>
|
|
434
|
+
</div>
|
|
435
|
+
<div
|
|
436
|
+
id="folder-view"
|
|
437
|
+
role="tabpanel"
|
|
438
|
+
tabindex="0"
|
|
439
|
+
class="h-32 p-4 text-sm focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-focus-indicator"
|
|
440
|
+
[attr.aria-labelledby]="selected() ? 'folder-tab-' + selected()?.id : null">
|
|
441
|
+
@if (selected(); as folder) {
|
|
442
|
+
<p>{{ folder.name }} holds {{ folder.items }} items.</p>
|
|
443
|
+
} @else {
|
|
444
|
+
<p>No folders are open.</p>
|
|
445
|
+
}
|
|
446
|
+
</div>
|
|
447
|
+
</div>
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
The tab and its panel still name each other, so assistive technology can go from one to the other:
|
|
451
|
+
|
|
452
|
+
- `panelId` on each `mona-tab` is the id of the panel you render. The tab names it in `aria-controls`. Tabs can share one panel when the page shows one place at a time, as above. A tab without a `panelId` has no `aria-controls`.
|
|
453
|
+
- `tabId` on each `mona-tab` is the id of the tab element. Set it to know it, or read it back from the tab when it's generated. Point the panel's `aria-labelledby` at the selected tab's `tabId`.
|
|
454
|
+
- Give the panel `role="tabpanel"` and, unless the first thing in it takes focus, `tabindex="0"`.
|
|
455
|
+
|
|
456
|
+
```html
|
|
457
|
+
<mona-tab-strip aria-label="Open folders" look="pill" [(selectedIndex)]="selectedIndex">
|
|
458
|
+
@for (folder of folders(); track folder.id) {
|
|
459
|
+
<mona-tab [tabId]="'folder-tab-' + folder.id" panelId="folder-view" [title]="folder.name"></mona-tab>
|
|
460
|
+
}
|
|
461
|
+
</mona-tab-strip>
|
|
462
|
+
|
|
463
|
+
<div id="folder-view" role="tabpanel" tabindex="0" [attr.aria-labelledby]="'folder-tab-' + selected().id">...</div>
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
In `mona-tabs`, `tabId` and `panelId` set the ids of the tab and of the panel the component renders, and both are generated when they're empty.
|
|
467
|
+
|
|
468
|
+
`Tab` on a strip goes to the next control after it, such as a new-tab button, rather than into the panel, since the panel may be anywhere on the page. See [A strip in a row of controls](#a-strip-in-a-row-of-controls) for the layout.
|
|
469
|
+
|
|
319
470
|
### Migrating from the removed `rounded` input
|
|
320
471
|
|
|
321
|
-
The `rounded` input has been removed.
|
|
472
|
+
The `rounded` input has been removed. The tab strip is separated from the content by a rule and the active tab is marked by an indicator line, so no radius is applied to the strip or the content. For rounded tabs, use the [pill look](#the-pill-look).
|
|
322
473
|
|
|
323
474
|
```text
|
|
324
475
|
Before:
|
|
325
476
|
<mona-tabs rounded="large">
|
|
326
477
|
|
|
327
|
-
After:
|
|
478
|
+
After, with the line look:
|
|
328
479
|
<mona-tabs>
|
|
480
|
+
|
|
481
|
+
After, with rounded tabs:
|
|
482
|
+
<mona-tabs look="pill">
|
|
329
483
|
```
|
|
330
484
|
|
|
331
485
|
Tab content no longer receives a default card-like surface. Consumers that need that appearance should wrap their tab content in `mona-card` or apply their own surface styles.
|
|
@@ -386,7 +540,7 @@ export class TabsCancelSelectExampleComponent {
|
|
|
386
540
|
|
|
387
541
|
### Tabs are removed by the consumer
|
|
388
542
|
|
|
389
|
-
`TabsComponent`
|
|
543
|
+
`TabsComponent` and `TabStripComponent` do not remove a `<mona-tab>` from the DOM when it is closed. `tabClose` only notifies the consumer that a close was requested (by clicking the close button, pressing Delete/Backspace on a tab, or middle-clicking it); the consumer is responsible for removing the corresponding tab from whatever collection drives the projected `<mona-tab>` elements (typically an `@for` loop).
|
|
390
544
|
|
|
391
545
|
### What happens when the selected tab goes away
|
|
392
546
|
|
|
@@ -412,6 +566,20 @@ Changing a tab's `title`, `disabled` or `closable` leaves its panel and everythi
|
|
|
412
566
|
|
|
413
567
|
When the tab strip overflows its container, scroll buttons appear automatically — this is not controlled by a public input. Top and bottom strips overflow horizontally (left/right scroll buttons); left and right strips overflow vertically (up/down scroll buttons). The scroll buttons are hidden from assistive technology and are not a Tab stop. Keyboard users can still reach tabs outside the visible area because moving focus with the arrow keys scrolls the newly focused tab into view. A tab selected by code is scrolled into view within the strip, without scrolling the page. Scroll buttons don't animate when the user asks for reduced motion.
|
|
414
568
|
|
|
569
|
+
### A strip in a row of controls
|
|
570
|
+
|
|
571
|
+
A `mona-tab-strip` is as wide as its tabs and shrinks with the row it's in, down to nothing, scrolling its tabs once they don't fit. In a titlebar, put it in a flex row and let the space after it grow, so the strip gives way before the controls around it:
|
|
572
|
+
|
|
573
|
+
```html
|
|
574
|
+
<header class="flex h-12 items-center gap-1">
|
|
575
|
+
<mona-tab-strip aria-label="Open folders" look="pill" size="small">...</mona-tab-strip>
|
|
576
|
+
<button monaButton look="ghost" [iconOnly]="true" aria-label="New tab" (click)="add()">+</button>
|
|
577
|
+
<div class="h-full min-w-6 flex-1"></div>
|
|
578
|
+
</header>
|
|
579
|
+
```
|
|
580
|
+
|
|
581
|
+
The strip is only as tall as its tabs, so center it in a taller row. With the pill look it draws no rule along its edge. A strip is always horizontal.
|
|
582
|
+
|
|
415
583
|
### Vertical layout constraints
|
|
416
584
|
|
|
417
585
|
A left or right tab strip needs a constrained available height. If the strip is as tall as its content, the tabs have no room to scroll and overflow tabs become unreachable. Give the `mona-tabs` host a bounded height (for example `class="h-96"`) when using `position="left"` or `position="right"`.
|
|
@@ -433,14 +601,14 @@ Not applicable. `TabsComponent` and `TabComponent` are not form controls and do
|
|
|
433
601
|
| `Home` / `End` | Select the first/last enabled tab. |
|
|
434
602
|
| `Delete` / `Backspace` | Close the tab that has focus, if it is closable and not disabled. |
|
|
435
603
|
| `Control+Shift` with the strip's arrow keys, `Home` or `End` (`Command+Shift` on macOS) | With `sortable`: move the focused tab one place, or to the start or end of the strip. |
|
|
436
|
-
| `Tab` | Moves focus from the tab strip into the selected tab's panel.
|
|
604
|
+
| `Tab` | Moves focus from the tab strip into the selected tab's panel. In `mona-tab-strip`, moves on to the next control after the strip. |
|
|
437
605
|
| `Shift+Tab` (while the panel itself has focus) | Moves focus back to the selected tab. |
|
|
438
606
|
|
|
439
607
|
In a right-to-left layout, `ArrowLeft` and `ArrowRight` swap, so they still follow the strip.
|
|
440
608
|
|
|
441
609
|
These keys are left to the browser when `Alt`, `Ctrl` or `Meta` is held, so `Alt+ArrowLeft` still goes back, and when `Shift` is held on the arrows, except for the moves of a `sortable` strip.
|
|
442
610
|
|
|
443
|
-
The close button on each tab is not a Tab stop; keyboard users close a tab with `Delete`/`Backspace` instead of activating the close button directly.
|
|
611
|
+
The close button on each tab is not a Tab stop; keyboard users close a tab with `Delete`/`Backspace` instead of activating the close button directly. With a pointer, a middle-click on a tab that can close does the same as its close button.
|
|
444
612
|
|
|
445
613
|
A vetoed tab can have focus without being selected. `Tab` still goes to the selected tab's panel, and coming back lands on the selected tab.
|
|
446
614
|
|
|
@@ -457,14 +625,17 @@ The selected tab is the only tab in the Tab order (`tabindex="0"`); all other ta
|
|
|
457
625
|
| Tab list | `aria-labelledby` | When the `aria-labelledby` input is set | The input's value |
|
|
458
626
|
| Tab list | `aria-orientation` | Always | `"horizontal"` for top/bottom positions, `"vertical"` for left/right |
|
|
459
627
|
| Tab | `role` | Always | `"tab"` |
|
|
628
|
+
| Tab | `id` | Always | The tab's `tabId`, generated when it isn't set |
|
|
460
629
|
| Tab | `aria-selected` | Always | Reflects whether the tab is the active tab |
|
|
461
630
|
| Tab | `aria-disabled` | Always | Reflects the tab's effective disabled state (own `disabled`, or the parent's `disabled`) |
|
|
462
|
-
| Tab | `aria-controls` | Always
|
|
631
|
+
| Tab | `aria-controls` | Always in `mona-tabs`; in `mona-tab-strip`, when the tab has a `panelId` | The corresponding panel's element id: the tab's `panelId`, or the generated id of the panel `mona-tabs` renders |
|
|
463
632
|
| Tab | `aria-keyshortcuts` | The tab can close, or the strip is `sortable`, and the tab isn't disabled | `"Delete Backspace"` when it can close, then the moves, such as `"Control+Shift+ArrowLeft Control+Shift+ArrowRight Control+Shift+Home Control+Shift+End"` |
|
|
464
633
|
| Panel | `role` | Always | `"tabpanel"` |
|
|
465
634
|
| Panel | `aria-hidden` | Always | `"true"` on a kept panel that isn't the active one, otherwise `"false"` |
|
|
466
635
|
| Panel | `aria-labelledby` | Always | The corresponding tab's element id |
|
|
467
636
|
|
|
637
|
+
The panel rows are for `mona-tabs`. With `mona-tab-strip`, the panel is yours: give it `role="tabpanel"` and an `aria-labelledby` naming the selected tab's `tabId`, as in [Tabs whose panels are elsewhere](#tabs-whose-panels-are-elsewhere).
|
|
638
|
+
|
|
468
639
|
Give the tab list a name with `aria-label` or `aria-labelledby` on `mona-tabs` when the page has more than one set of tabs, or when nothing nearby says what they're for. The inputs go to the tab list, not the host.
|
|
469
640
|
|
|
470
641
|
A tab list may only contain tabs, and a tab's content is presentational, so a close button can't be exposed in either place. Axe rejects one anywhere inside the tab list, even beside the tab. That's why the visible close button, which is there for the pointer, is hidden from assistive technology with `aria-hidden` and `tabindex="-1"`. Each closable tab also gets a visually hidden button after the tab list, named "Close tab" plus the tab's title, which screen readers can reach and activate, including on touch devices. It's out of the Tab order too, since the keyboard's route is `Delete` or `Backspace`. Its text comes from `closeTab` in the `tabs` messages.
|
|
@@ -476,6 +647,7 @@ Everything below is imported from `@nanahoshi/mona-ui/tabs`. Each name links to
|
|
|
476
647
|
| Name | Kind | Description |
|
|
477
648
|
| --- | --- | --- |
|
|
478
649
|
| [`TabsComponent`](api/tabs.md#tabscomponent) | Component | |
|
|
650
|
+
| [`TabStripComponent`](api/tabs.md#tabstripcomponent) | Component | Only the tab list of a set of tabs, for when each tab's panel is somewhere else on the page, as with the tabs in a window's titlebar. |
|
|
479
651
|
| [`TabComponent`](api/tabs.md#tabcomponent) | Component | |
|
|
480
652
|
| [`TabContentTemplateDirective`](api/tabs.md#tabcontenttemplatedirective) | Directive | |
|
|
481
653
|
| [`TabTitleTemplateDirective`](api/tabs.md#tabtitletemplatedirective) | Directive | |
|
|
@@ -485,9 +657,10 @@ Everything below is imported from `@nanahoshi/mona-ui/tabs`. Each name links to
|
|
|
485
657
|
|
|
486
658
|
### Types
|
|
487
659
|
|
|
488
|
-
| Type | Kind |
|
|
489
|
-
| --- | --- |
|
|
490
|
-
| [`TABS_DEFAULT_MESSAGES`](api/tabs.md#tabs-default-messages) | Constant |
|
|
491
|
-
| [`
|
|
660
|
+
| Type | Kind | Description |
|
|
661
|
+
| --- | --- | --- |
|
|
662
|
+
| [`TABS_DEFAULT_MESSAGES`](api/tabs.md#tabs-default-messages) | Constant | |
|
|
663
|
+
| [`TabsLook`](api/tabs.md#tabslook) | Type alias | How a tab strip marks the selected tab. |
|
|
664
|
+
| [`TabsPosition`](api/tabs.md#tabsposition) | Type alias | |
|
|
492
665
|
|
|
493
666
|
**Related types:** [`MonaTabsMessages`](api/i18n.md#monatabsmessages), [`PreventableEvent`](api/common.md#preventableevent)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NgTemplateOutlet } from "@angular/common";
|
|
2
2
|
import * as i0 from "@angular/core";
|
|
3
|
-
import { Component, Directive, ElementRef, InjectionToken, Injector, TemplateRef, afterNextRender, booleanAttribute, computed, contentChild, contentChildren, forwardRef, inject, input, linkedSignal, output, viewChild } from "@angular/core";
|
|
3
|
+
import { Component, Directive, ElementRef, InjectionToken, Injector, TemplateRef, afterNextRender, afterRenderEffect, booleanAttribute, computed, contentChild, contentChildren, forwardRef, inject, input, linkedSignal, output, signal, untracked, viewChild } from "@angular/core";
|
|
4
4
|
import { LucideChevronRight, LucideEllipsis } from "@lucide/angular";
|
|
5
5
|
import { MonaI18nService } from "@nanahoshi/mona-ui/i18n";
|
|
6
6
|
import { twMerge } from "tailwind-merge";
|
|
@@ -15,7 +15,7 @@ const breadcrumbListThemeVariants = cva(`
|
|
|
15
15
|
} } });
|
|
16
16
|
const breadcrumbListItemWrapperThemeVariants = cva(`flex min-w-0 items-center`, { variants: { current: {
|
|
17
17
|
true: "",
|
|
18
|
-
false: "shrink-[
|
|
18
|
+
false: "shrink-[1000000]"
|
|
19
19
|
} } });
|
|
20
20
|
const breadcrumbListItemThemeVariants = cva(`
|
|
21
21
|
flex h-full max-w-full min-w-0 items-center px-1
|
|
@@ -370,35 +370,52 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
370
370
|
}]
|
|
371
371
|
}
|
|
372
372
|
});
|
|
373
|
+
const FIT_TOLERANCE = .01;
|
|
374
|
+
const FOCUSABLE_ITEM = "a:not([aria-disabled='true']), button:not(:disabled)";
|
|
373
375
|
function numberOrNull(value) {
|
|
374
376
|
if (value == null || value === "") return null;
|
|
375
377
|
const parsed = Number(value);
|
|
376
378
|
return Number.isNaN(parsed) ? null : parsed;
|
|
377
379
|
}
|
|
380
|
+
function pixels(value) {
|
|
381
|
+
return parseFloat(value) || 0;
|
|
382
|
+
}
|
|
383
|
+
function itemsToFold(widths) {
|
|
384
|
+
const { available, foldButton, gap, items, separators } = widths;
|
|
385
|
+
const fits = (width) => width <= available + FIT_TOLERANCE;
|
|
386
|
+
const most = items.length - 2;
|
|
387
|
+
let width = items.reduce((total, item) => total + item, 0) + separators.reduce((total, separator) => total + separator, 0) + gap * (items.length * 2 - 2);
|
|
388
|
+
if (most < 1 || fits(width)) return 0;
|
|
389
|
+
width += foldButton - items[1];
|
|
390
|
+
for (let folded = 1; folded < most; folded++) {
|
|
391
|
+
if (fits(width)) return folded;
|
|
392
|
+
width -= items[folded + 1] + separators[folded] + gap * 2;
|
|
393
|
+
}
|
|
394
|
+
return most;
|
|
395
|
+
}
|
|
378
396
|
var BreadcrumbComponent = class BreadcrumbComponent {
|
|
397
|
+
#foldedToFit;
|
|
398
|
+
#i18n;
|
|
399
|
+
#injector;
|
|
400
|
+
#resized;
|
|
379
401
|
constructor() {
|
|
402
|
+
this.#foldedToFit = signal(0, ...ngDevMode ? [{ debugName: "#foldedToFit" }] : /* istanbul ignore next */ []);
|
|
380
403
|
this.#i18n = inject(MonaI18nService);
|
|
381
404
|
this.#injector = inject(Injector);
|
|
405
|
+
this.#resized = signal(0, ...ngDevMode ? [{ debugName: "#resized" }] : /* istanbul ignore next */ []);
|
|
382
406
|
this.currentItemClass = computed(() => {
|
|
383
407
|
return breadcrumbCurrentItemThemeVariants();
|
|
384
408
|
}, ...ngDevMode ? [{ debugName: "currentItemClass" }] : /* istanbul ignore next */ []);
|
|
385
409
|
this.entries = computed(() => {
|
|
386
410
|
const items = this.itemComponents();
|
|
387
411
|
const hidden = this.hiddenCount();
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
if (hidden === 0 || index === 0 || index > hidden) entries.push({
|
|
396
|
-
index,
|
|
397
|
-
item,
|
|
398
|
-
key: item
|
|
399
|
-
});
|
|
400
|
-
});
|
|
401
|
-
return entries;
|
|
412
|
+
return items.map((item, index) => ({
|
|
413
|
+
foldButtonBefore: index === 1 && items.length > 2,
|
|
414
|
+
folded: index > 0 && index <= hidden,
|
|
415
|
+
index,
|
|
416
|
+
item,
|
|
417
|
+
separatorFolded: index > 0 && index < hidden
|
|
418
|
+
}));
|
|
402
419
|
}, ...ngDevMode ? [{ debugName: "entries" }] : /* istanbul ignore next */ []);
|
|
403
420
|
this.expanded = linkedSignal({
|
|
404
421
|
...ngDevMode ? { debugName: "expanded" } : /* istanbul ignore next */ {},
|
|
@@ -407,10 +424,11 @@ var BreadcrumbComponent = class BreadcrumbComponent {
|
|
|
407
424
|
});
|
|
408
425
|
this.hasItems = computed(() => this.itemComponents().length > 0, ...ngDevMode ? [{ debugName: "hasItems" }] : /* istanbul ignore next */ []);
|
|
409
426
|
this.hiddenCount = computed(() => {
|
|
410
|
-
const maxItems = this.maxItems();
|
|
411
427
|
const count = this.itemComponents().length;
|
|
412
|
-
if (
|
|
413
|
-
|
|
428
|
+
if (count < 3 || this.expanded()) return 0;
|
|
429
|
+
const maxItems = this.maxItems();
|
|
430
|
+
const byCount = maxItems === null ? 0 : count - Math.max(Math.trunc(maxItems), 2);
|
|
431
|
+
return Math.min(Math.max(byCount, this.#foldedToFit()), count - 2);
|
|
414
432
|
}, ...ngDevMode ? [{ debugName: "hiddenCount" }] : /* istanbul ignore next */ []);
|
|
415
433
|
this.itemComponents = contentChildren(BreadcrumbItemComponent, ...ngDevMode ? [{ debugName: "itemComponents" }] : /* istanbul ignore next */ []);
|
|
416
434
|
this.itemContentClass = computed(() => {
|
|
@@ -451,30 +469,95 @@ var BreadcrumbComponent = class BreadcrumbComponent {
|
|
|
451
469
|
...ngDevMode ? { debugName: "userClass" } : /* istanbul ignore next */ {},
|
|
452
470
|
alias: "class"
|
|
453
471
|
});
|
|
472
|
+
afterRenderEffect((onCleanup) => {
|
|
473
|
+
this.itemComponents();
|
|
474
|
+
const list = this.listElement()?.nativeElement;
|
|
475
|
+
if (list == null || typeof ResizeObserver === "undefined") return;
|
|
476
|
+
const observer = new ResizeObserver(() => this.#resized.update((count) => count + 1));
|
|
477
|
+
observer.observe(list);
|
|
478
|
+
for (const entry of Array.from(list.children)) observer.observe(entry);
|
|
479
|
+
onCleanup(() => observer.disconnect());
|
|
480
|
+
});
|
|
481
|
+
afterRenderEffect(() => {
|
|
482
|
+
this.itemComponents();
|
|
483
|
+
this.lastItemCurrent();
|
|
484
|
+
this.#resized();
|
|
485
|
+
const list = this.listElement()?.nativeElement;
|
|
486
|
+
if (list != null && !this.expanded()) untracked(() => this.#fold(list));
|
|
487
|
+
});
|
|
454
488
|
}
|
|
455
|
-
#i18n;
|
|
456
|
-
#injector;
|
|
457
489
|
expand() {
|
|
458
|
-
const firstRevealed = 1;
|
|
459
490
|
const lastRevealed = this.hiddenCount();
|
|
460
491
|
this.expanded.set(true);
|
|
492
|
+
this.#focusItemAfterRender(1, lastRevealed);
|
|
493
|
+
}
|
|
494
|
+
listItemClass(current) {
|
|
495
|
+
return breadcrumbListItemWrapperThemeVariants({ current });
|
|
496
|
+
}
|
|
497
|
+
onItemClick(item, event) {
|
|
498
|
+
if (!item.effectiveDisabled()) item.itemClick.emit(event);
|
|
499
|
+
}
|
|
500
|
+
#fold(list) {
|
|
501
|
+
const focused = list.ownerDocument.activeElement;
|
|
502
|
+
const before = this.hiddenCount();
|
|
503
|
+
const widths = this.#measure(list);
|
|
504
|
+
this.#foldedToFit.set(widths == null ? 0 : itemsToFold(widths));
|
|
505
|
+
const after = this.hiddenCount();
|
|
506
|
+
if (after === before || !(focused instanceof HTMLElement) || !list.contains(focused)) return;
|
|
507
|
+
if (after === 0 && focused.closest("[data-breadcrumb-fold]") != null) {
|
|
508
|
+
this.#focusItemAfterRender(1, before);
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
const index = Number(focused.closest("[data-item-index]")?.getAttribute("data-item-index"));
|
|
512
|
+
if (index > 0 && index <= after) afterNextRender({ read: () => list.querySelector("[data-breadcrumb-expand]")?.focus() }, { injector: this.#injector });
|
|
513
|
+
}
|
|
514
|
+
#focusItemAfterRender(first, last) {
|
|
461
515
|
afterNextRender({ read: () => {
|
|
462
516
|
const list = this.listElement()?.nativeElement;
|
|
463
|
-
for (let index =
|
|
464
|
-
const target = list?.querySelector(`li[data-item-index="${index}"]`)?.querySelector(
|
|
517
|
+
for (let index = first; index <= last; index++) {
|
|
518
|
+
const target = list?.querySelector(`li[data-item-index="${index}"]`)?.querySelector(FOCUSABLE_ITEM);
|
|
465
519
|
if (target) {
|
|
466
520
|
target.focus();
|
|
467
521
|
return;
|
|
468
522
|
}
|
|
469
523
|
}
|
|
470
|
-
list?.querySelector(
|
|
524
|
+
list?.querySelector(FOCUSABLE_ITEM)?.focus();
|
|
471
525
|
} }, { injector: this.#injector });
|
|
472
526
|
}
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
527
|
+
#measure(list) {
|
|
528
|
+
const view = list.ownerDocument.defaultView;
|
|
529
|
+
if (view == null || this.itemComponents().length < 3) return null;
|
|
530
|
+
const entries = Array.from(list.children).filter((entry) => entry instanceof HTMLElement);
|
|
531
|
+
const folded = entries.filter((entry) => entry.hidden);
|
|
532
|
+
for (const entry of folded) {
|
|
533
|
+
entry.hidden = false;
|
|
534
|
+
entry.style.display = "";
|
|
535
|
+
}
|
|
536
|
+
for (const entry of entries) entry.style.flexShrink = "0";
|
|
537
|
+
const listStyle = view.getComputedStyle(list);
|
|
538
|
+
const insets = listStyle.boxSizing === "border-box" ? pixels(listStyle.paddingLeft) + pixels(listStyle.paddingRight) + pixels(listStyle.borderLeftWidth) + pixels(listStyle.borderRightWidth) : 0;
|
|
539
|
+
const items = [];
|
|
540
|
+
const separators = [];
|
|
541
|
+
let foldButton = 0;
|
|
542
|
+
for (const entry of entries) {
|
|
543
|
+
const width = pixels(view.getComputedStyle(entry).width);
|
|
544
|
+
if (entry.hasAttribute("data-item-index")) items.push(width);
|
|
545
|
+
else if (entry.hasAttribute("data-breadcrumb-fold")) foldButton = width;
|
|
546
|
+
else separators.push(width);
|
|
547
|
+
}
|
|
548
|
+
const widths = {
|
|
549
|
+
available: pixels(listStyle.width) - insets,
|
|
550
|
+
foldButton,
|
|
551
|
+
gap: pixels(listStyle.columnGap),
|
|
552
|
+
items,
|
|
553
|
+
separators
|
|
554
|
+
};
|
|
555
|
+
for (const entry of entries) entry.style.flexShrink = "";
|
|
556
|
+
for (const entry of folded) {
|
|
557
|
+
entry.hidden = true;
|
|
558
|
+
entry.style.display = "none";
|
|
559
|
+
}
|
|
560
|
+
return widths;
|
|
478
561
|
}
|
|
479
562
|
static {
|
|
480
563
|
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
@@ -561,7 +644,7 @@ var BreadcrumbComponent = class BreadcrumbComponent {
|
|
|
561
644
|
isSignal: true
|
|
562
645
|
}],
|
|
563
646
|
ngImport: i0,
|
|
564
|
-
template: "@if (itemComponents().length > 0) {\n <ol #list role=\"list\" [class]=\"listClass()\">\n @for (entry of entries(); track entry.
|
|
647
|
+
template: "@if (itemComponents().length > 0) {\n <!--\n Folded entries stay in the list, so the trail can be measured whole. The hidden attribute alone would lose to an\n entry's display class.\n -->\n <ol #list role=\"list\" [class]=\"listClass()\">\n @for (entry of entries(); track entry.item) {\n @let item = entry.item;\n @if (entry.foldButtonBefore) {\n <li\n class=\"shrink-0\"\n data-breadcrumb-fold\n [hidden]=\"hiddenCount() === 0\"\n [style.display]=\"hiddenCount() === 0 ? 'none' : null\">\n <button\n type=\"button\"\n monaBreadcrumbItem\n data-breadcrumb-expand\n [disabled]=\"disabled()\"\n [attr.aria-label]=\"messages().showFullPath\"\n (click)=\"expand()\">\n <svg lucideEllipsis [size]=\"18\" aria-hidden=\"true\"></svg>\n </button>\n </li>\n }\n <li\n [class]=\"listItemClass(item.current())\"\n [attr.data-item-index]=\"entry.index\"\n [hidden]=\"entry.folded\"\n [style.display]=\"entry.folded ? 'none' : null\">\n @if (item.link()) {\n <!-- The anchor is the item, with its own classes and aria-current. -->\n <ng-container [ngTemplateOutlet]=\"item.templateRef()\"></ng-container>\n } @else if (item.current()) {\n <span aria-current=\"page\" [class]=\"currentItemClass()\">\n <ng-container [ngTemplateOutlet]=\"item.templateRef()\"></ng-container>\n </span>\n } @else {\n <button\n type=\"button\"\n monaBreadcrumbItem\n [disabled]=\"item.effectiveDisabled()\"\n (click)=\"onItemClick(item, $event)\">\n <span [class]=\"itemContentClass()\">\n <ng-container [ngTemplateOutlet]=\"item.templateRef()\"></ng-container>\n </span>\n </button>\n }\n </li>\n\n @if (!$last) {\n <li\n class=\"shrink-0\"\n aria-hidden=\"true\"\n role=\"presentation\"\n [hidden]=\"entry.separatorFolded\"\n [style.display]=\"entry.separatorFolded ? 'none' : null\">\n @if (separatorTemplate()) {\n <ng-container\n [ngTemplateOutlet]=\"separatorTemplate()\"\n [ngTemplateOutletContext]=\"{ $implicit: entry.index }\"></ng-container>\n } @else {\n <svg lucideChevronRight [size]=\"18\" class=\"rtl:rotate-180\"></svg>\n }\n </li>\n }\n }\n </ol>\n}\n",
|
|
565
648
|
dependencies: [
|
|
566
649
|
{
|
|
567
650
|
kind: "directive",
|
|
@@ -617,9 +700,10 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
617
700
|
"[attr.role]": "hasItems() ? 'navigation' : null",
|
|
618
701
|
class: "block max-w-full min-w-0"
|
|
619
702
|
},
|
|
620
|
-
template: "@if (itemComponents().length > 0) {\n <ol #list role=\"list\" [class]=\"listClass()\">\n @for (entry of entries(); track entry.
|
|
703
|
+
template: "@if (itemComponents().length > 0) {\n <!--\n Folded entries stay in the list, so the trail can be measured whole. The hidden attribute alone would lose to an\n entry's display class.\n -->\n <ol #list role=\"list\" [class]=\"listClass()\">\n @for (entry of entries(); track entry.item) {\n @let item = entry.item;\n @if (entry.foldButtonBefore) {\n <li\n class=\"shrink-0\"\n data-breadcrumb-fold\n [hidden]=\"hiddenCount() === 0\"\n [style.display]=\"hiddenCount() === 0 ? 'none' : null\">\n <button\n type=\"button\"\n monaBreadcrumbItem\n data-breadcrumb-expand\n [disabled]=\"disabled()\"\n [attr.aria-label]=\"messages().showFullPath\"\n (click)=\"expand()\">\n <svg lucideEllipsis [size]=\"18\" aria-hidden=\"true\"></svg>\n </button>\n </li>\n }\n <li\n [class]=\"listItemClass(item.current())\"\n [attr.data-item-index]=\"entry.index\"\n [hidden]=\"entry.folded\"\n [style.display]=\"entry.folded ? 'none' : null\">\n @if (item.link()) {\n <!-- The anchor is the item, with its own classes and aria-current. -->\n <ng-container [ngTemplateOutlet]=\"item.templateRef()\"></ng-container>\n } @else if (item.current()) {\n <span aria-current=\"page\" [class]=\"currentItemClass()\">\n <ng-container [ngTemplateOutlet]=\"item.templateRef()\"></ng-container>\n </span>\n } @else {\n <button\n type=\"button\"\n monaBreadcrumbItem\n [disabled]=\"item.effectiveDisabled()\"\n (click)=\"onItemClick(item, $event)\">\n <span [class]=\"itemContentClass()\">\n <ng-container [ngTemplateOutlet]=\"item.templateRef()\"></ng-container>\n </span>\n </button>\n }\n </li>\n\n @if (!$last) {\n <li\n class=\"shrink-0\"\n aria-hidden=\"true\"\n role=\"presentation\"\n [hidden]=\"entry.separatorFolded\"\n [style.display]=\"entry.separatorFolded ? 'none' : null\">\n @if (separatorTemplate()) {\n <ng-container\n [ngTemplateOutlet]=\"separatorTemplate()\"\n [ngTemplateOutletContext]=\"{ $implicit: entry.index }\"></ng-container>\n } @else {\n <svg lucideChevronRight [size]=\"18\" class=\"rtl:rotate-180\"></svg>\n }\n </li>\n }\n }\n </ol>\n}\n"
|
|
621
704
|
}]
|
|
622
705
|
}],
|
|
706
|
+
ctorParameters: () => [],
|
|
623
707
|
propDecorators: {
|
|
624
708
|
itemComponents: [{
|
|
625
709
|
type: i0.ContentChildren,
|