svelte-fluentui 1.5.0 β 1.6.0-rc01
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/README.md +6 -6
- package/dist/components/Tab.svelte +18 -0
- package/dist/components/Tab.svelte.d.ts +14 -0
- package/dist/components/Tabs.svelte +45 -3
- package/dist/components/Tabs.svelte.d.ts +15 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,6 +4,12 @@ A comprehensive Svelte component library for the Microsoft FluentUI design syste
|
|
|
4
4
|
|
|
5
5
|
π **[Live documentation & showcase β svelte-fluentui.keenmate.dev](https://svelte-fluentui.keenmate.dev)**
|
|
6
6
|
|
|
7
|
+
## What's New in v1.6.0-rc01
|
|
8
|
+
|
|
9
|
+
- **`Tabs` β `canLeave` guard to block switching away from a tab with unsaved changes** β Give the active `<Tab>` a `canLeave` callback and `Tabs` calls it before navigating anywhere else, cancelling the switch if it returns `false`. Because `Tabs` renders its own tablist and owns every switch, there was no veto point before β clicking another tab simply switched, even mid-edit. The guard now sits at a single chokepoint that covers click, keyboard, swipe, and overflow-menu navigation, and it's async, so you can `await confirm(...)` or a save prompt instead of only blocking synchronously. Assigning `activeId` directly still bypasses it by design β that's your own navigation to gate.
|
|
10
|
+
- **`Tabs` β `canClose` guard to confirm before a tab's Γ button destroys it** β Separate from `canLeave` because leaving keeps a tab alive while closing throws it away: `canClose` runs before the close button fires `oncloseclick`, and a `false` (or a `Promise<boolean>` resolving false) cancels the close. It guards the specific tab being closed rather than the active one, and it's async-capable for confirm dialogs. The closable-tabs demo now confirms on close for every file except `Notes.txt`, which is left unguarded to show the opt-out.
|
|
11
|
+
- **`Tabs` β docs corrected and the dead `overflow` prop removed** β The page used to claim Tabs are "built on `<fluent-tab>`", but the Svelte rewrite renders native `<button role="tab">` elements and only reaches for a FluentUI web component (`<fluent-menu>`) in the overflow menu β the description now reflects that. The long-deprecated `overflow` prop (it warned and did nothing, replaced by `responsive="menu"`) is gone from both API tables and its redundant demo, and new `canLeave` / `canClose` rows and demos were added.
|
|
12
|
+
|
|
7
13
|
## What's New in v1.5.0
|
|
8
14
|
|
|
9
15
|
The first stable release of the 1.5.0 line (promoted from the rc01βrc08 series). The highlights across the whole line:
|
|
@@ -16,12 +22,6 @@ The first stable release of the 1.5.0 line (promoted from the rc01βrc08 series
|
|
|
16
22
|
- **`Grid` β container-query breakpoints** β An opt-in `container` mode resolves `xs`/`sm`/`md`β¦ against a Grid's own width instead of the viewport, so it reflows inside sidebars, panels, and splitters, with app-wide and per-Grid breakpoint configuration delivered CSP-safely via constructed stylesheets.
|
|
17
23
|
- **`Dialog` β focus-trap freeze and modal scroll-lock fixes** β Two open dialogs no longer ping-pong focus into a stack-overflow `RangeError` (browser freeze), and modal dialogs now lock body scroll so wheeling over the dialog no longer scrolls the page behind it.
|
|
18
24
|
|
|
19
|
-
## What's New in v1.5.0-rc08
|
|
20
|
-
|
|
21
|
-
- **`Autocomplete` β the dropdown now opens when initial options arrive after focus** β With `showInitialOptions` and an autofocused control, the on-focus handler ran before the background fetch had populated `options`, so the dropdown stayed shut; when the data later resolved, nothing re-opened it and the loaded items sat inaccessible until you typed β which needlessly re-ran the (often server-side) search. A reactive effect now opens the dropdown on the `options` emptyβpopulated transition while the input is focused with an empty query. It's gated on that transition, so pressing `Escape` to dismiss it while still focused doesn't immediately re-open, and it respects disabled/readonly and existing single-select values.
|
|
22
|
-
- **`Accordion` β `end`-slot content no longer sits flush against the card edge with `togglePosition="start"`** β The heading is a 4-column grid whose order flips with `togglePosition`: in the default (`end`) mode the chevron was the rightmost cell and its margin supplied the right-edge inset. With the toggle on the leading edge, the `end` slot becomes rightmost but had no trailing inset of its own, so chips / badges / buttons in it pressed against the card border. The `end` slot now carries a matching `padding-inline-end` (8px, via `--design-unit`) in start-toggle mode, restoring the inset the chevron used to provide.
|
|
23
|
-
- **`Label` β resolved a `.fluent-label` class-name collision that shifted the tag chip off-centre** β The `Label` tag/chip component and the canonical form-field label helper (bold, block, sits above stacked inputs) both used the class `.fluent-label`; the helper's `margin-bottom: 0.25rem` leaked into every `<Label>`, nudging the chip up off the centre line inside a flex row. The form-field helper is renamed to **`.fluent-field-label`** (the honest name), freeing `.fluent-label` for the `Label` component alone and removing the collision at the source. **Potentially breaking** for anyone who hand-wrote `class="fluent-label"` to borrow the form-field label styling β switch those to `class="fluent-field-label"`.
|
|
24
|
-
|
|
25
25
|
For the full history, see the [CHANGELOG](https://github.com/KeenMate/svelte-fluentui/blob/prod/CHANGELOG.md).
|
|
26
26
|
|
|
27
27
|
## Features
|
|
@@ -19,6 +19,20 @@
|
|
|
19
19
|
visible?: boolean
|
|
20
20
|
/** Arbitrary context data passed to `ontabchange` when this tab becomes active. */
|
|
21
21
|
data?: Record<string, unknown>
|
|
22
|
+
/**
|
|
23
|
+
* Guard called before Tabs navigates away from this tab while it is
|
|
24
|
+
* active. Return `false` (or a Promise resolving to `false`) to veto
|
|
25
|
+
* the switch β e.g. when the tab has unsaved changes. May be async so
|
|
26
|
+
* it can await a confirm dialog.
|
|
27
|
+
*/
|
|
28
|
+
canLeave?: () => boolean | Promise<boolean>
|
|
29
|
+
/**
|
|
30
|
+
* Guard called before this tab's close (Γ) button fires `oncloseclick`.
|
|
31
|
+
* Return `false` (or a Promise resolving to `false`) to veto the close β
|
|
32
|
+
* e.g. to confirm discarding unsaved data. Independent of `canLeave`.
|
|
33
|
+
* May be async so it can await a confirm dialog.
|
|
34
|
+
*/
|
|
35
|
+
canClose?: () => boolean | Promise<boolean>
|
|
22
36
|
oncloseclick?: () => void
|
|
23
37
|
}
|
|
24
38
|
|
|
@@ -37,6 +51,8 @@
|
|
|
37
51
|
showClose = false,
|
|
38
52
|
visible = true,
|
|
39
53
|
data = undefined,
|
|
54
|
+
canLeave = undefined,
|
|
55
|
+
canClose = undefined,
|
|
40
56
|
oncloseclick = undefined
|
|
41
57
|
}: Props = $props()
|
|
42
58
|
|
|
@@ -78,6 +94,8 @@
|
|
|
78
94
|
showClose,
|
|
79
95
|
visible,
|
|
80
96
|
data,
|
|
97
|
+
canLeave,
|
|
98
|
+
canClose,
|
|
81
99
|
oncloseclick,
|
|
82
100
|
class: className,
|
|
83
101
|
style
|
|
@@ -15,6 +15,20 @@ type Props = {
|
|
|
15
15
|
visible?: boolean;
|
|
16
16
|
/** Arbitrary context data passed to `ontabchange` when this tab becomes active. */
|
|
17
17
|
data?: Record<string, unknown>;
|
|
18
|
+
/**
|
|
19
|
+
* Guard called before Tabs navigates away from this tab while it is
|
|
20
|
+
* active. Return `false` (or a Promise resolving to `false`) to veto
|
|
21
|
+
* the switch β e.g. when the tab has unsaved changes. May be async so
|
|
22
|
+
* it can await a confirm dialog.
|
|
23
|
+
*/
|
|
24
|
+
canLeave?: () => boolean | Promise<boolean>;
|
|
25
|
+
/**
|
|
26
|
+
* Guard called before this tab's close (Γ) button fires `oncloseclick`.
|
|
27
|
+
* Return `false` (or a Promise resolving to `false`) to veto the close β
|
|
28
|
+
* e.g. to confirm discarding unsaved data. Independent of `canLeave`.
|
|
29
|
+
* May be async so it can await a confirm dialog.
|
|
30
|
+
*/
|
|
31
|
+
canClose?: () => boolean | Promise<boolean>;
|
|
18
32
|
oncloseclick?: () => void;
|
|
19
33
|
};
|
|
20
34
|
declare const Tab: import("svelte").Component<Props, {}, "">;
|
|
@@ -19,6 +19,21 @@
|
|
|
19
19
|
showClose?: boolean
|
|
20
20
|
visible?: boolean
|
|
21
21
|
data?: Record<string, unknown>
|
|
22
|
+
/**
|
|
23
|
+
* Guard invoked on the *currently active* tab before Tabs navigates
|
|
24
|
+
* away from it. Return `false` (or a Promise resolving to `false`) to
|
|
25
|
+
* veto the switch β e.g. when the tab holds unsaved/dirty data. May be
|
|
26
|
+
* async so it can await a confirm dialog.
|
|
27
|
+
*/
|
|
28
|
+
canLeave?: () => boolean | Promise<boolean>
|
|
29
|
+
/**
|
|
30
|
+
* Guard invoked before this tab's close (Γ) button fires `oncloseclick`.
|
|
31
|
+
* Return `false` (or a Promise resolving to `false`) to veto the close β
|
|
32
|
+
* e.g. to confirm discarding unsaved data. Independent of `canLeave`:
|
|
33
|
+
* leaving keeps the tab alive, closing destroys it. Guards the tab being
|
|
34
|
+
* closed (not necessarily the active one). May be async.
|
|
35
|
+
*/
|
|
36
|
+
canClose?: () => boolean | Promise<boolean>
|
|
22
37
|
oncloseclick?: () => void
|
|
23
38
|
class?: string
|
|
24
39
|
style?: string
|
|
@@ -310,10 +325,27 @@
|
|
|
310
325
|
}
|
|
311
326
|
}
|
|
312
327
|
|
|
313
|
-
|
|
328
|
+
/*
|
|
329
|
+
* A tab can veto being navigated away from: before switching off the
|
|
330
|
+
* current tab we call its registered `canLeave()` guard (if any). A
|
|
331
|
+
* falsy resolve cancels the switch, so a tab with dirty data can prompt
|
|
332
|
+
* the user and stay put. The guard may be sync or async (return a
|
|
333
|
+
* Promise) so it can await a confirm dialog. Only interaction-driven
|
|
334
|
+
* switches (click, keyboard, swipe, overflow menu) route through here β
|
|
335
|
+
* a consumer assigning `activeId` directly bypasses the guard by design.
|
|
336
|
+
*/
|
|
337
|
+
async function canLeaveCurrent(targetId: string): Promise<boolean> {
|
|
338
|
+
if (!activeId || activeId === targetId) return true
|
|
339
|
+
const current = orderedTabs.find(t => t.id === activeId)
|
|
340
|
+
if (!current?.canLeave) return true
|
|
341
|
+
return (await current.canLeave()) !== false
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
async function selectTab(tabId: string, focus = false) {
|
|
314
345
|
const tab = orderedTabs.find(t => t.id === tabId)
|
|
315
346
|
if (!tab || tab.disabled) return
|
|
316
347
|
if (activeId !== tabId) {
|
|
348
|
+
if (!(await canLeaveCurrent(tabId))) return
|
|
317
349
|
activeId = tabId
|
|
318
350
|
ontabchange?.({ tabId, data: tab.data })
|
|
319
351
|
}
|
|
@@ -357,9 +389,16 @@
|
|
|
357
389
|
}
|
|
358
390
|
}
|
|
359
391
|
|
|
360
|
-
|
|
392
|
+
/*
|
|
393
|
+
* Close is guarded independently of navigation: a tab can allow being left
|
|
394
|
+
* (kept in memory) yet still confirm before being destroyed. We await the
|
|
395
|
+
* closed tab's `canClose()` (if any) before firing `oncloseclick`; a falsy
|
|
396
|
+
* resolve cancels the close.
|
|
397
|
+
*/
|
|
398
|
+
async function handleCloseClick(tab: TabEntry, e: MouseEvent) {
|
|
361
399
|
e.stopPropagation()
|
|
362
400
|
e.preventDefault()
|
|
401
|
+
if (tab.canClose && (await tab.canClose()) === false) return
|
|
363
402
|
tab.oncloseclick?.()
|
|
364
403
|
}
|
|
365
404
|
|
|
@@ -556,9 +595,12 @@
|
|
|
556
595
|
* position with the clicked tab, so the selection stays in the strip after
|
|
557
596
|
* it's activated. The displaced tab falls off into the overflow menu.
|
|
558
597
|
*/
|
|
559
|
-
function onOverflowTabClick(tabId: string) {
|
|
598
|
+
async function onOverflowTabClick(tabId: string) {
|
|
560
599
|
const tab = orderedTabs.find(t => t.id === tabId)
|
|
561
600
|
if (!tab || tab.disabled) return
|
|
601
|
+
// Guard before reordering/activating. When called from the auto-swap
|
|
602
|
+
// effect the tab is already active, so canLeaveCurrent short-circuits.
|
|
603
|
+
if (!(await canLeaveCurrent(tabId))) return
|
|
562
604
|
|
|
563
605
|
const currentOrder = displayOrder.length > 0
|
|
564
606
|
? [...displayOrder]
|
|
@@ -17,6 +17,21 @@ export type TabEntry = {
|
|
|
17
17
|
showClose?: boolean;
|
|
18
18
|
visible?: boolean;
|
|
19
19
|
data?: Record<string, unknown>;
|
|
20
|
+
/**
|
|
21
|
+
* Guard invoked on the *currently active* tab before Tabs navigates
|
|
22
|
+
* away from it. Return `false` (or a Promise resolving to `false`) to
|
|
23
|
+
* veto the switch β e.g. when the tab holds unsaved/dirty data. May be
|
|
24
|
+
* async so it can await a confirm dialog.
|
|
25
|
+
*/
|
|
26
|
+
canLeave?: () => boolean | Promise<boolean>;
|
|
27
|
+
/**
|
|
28
|
+
* Guard invoked before this tab's close (Γ) button fires `oncloseclick`.
|
|
29
|
+
* Return `false` (or a Promise resolving to `false`) to veto the close β
|
|
30
|
+
* e.g. to confirm discarding unsaved data. Independent of `canLeave`:
|
|
31
|
+
* leaving keeps the tab alive, closing destroys it. Guards the tab being
|
|
32
|
+
* closed (not necessarily the active one). May be async.
|
|
33
|
+
*/
|
|
34
|
+
canClose?: () => boolean | Promise<boolean>;
|
|
20
35
|
oncloseclick?: () => void;
|
|
21
36
|
class?: string;
|
|
22
37
|
style?: string;
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "1.
|
|
1
|
+
export declare const VERSION = "1.6.0-rc01";
|
package/dist/version.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// Auto-generated by scripts/pre-package.js β do NOT edit by hand.
|
|
2
2
|
// In dev this file holds whatever value was committed last; on each `npm run package`
|
|
3
3
|
// the pre-package script overwrites it with the current package.json version.
|
|
4
|
-
export const VERSION = "1.
|
|
4
|
+
export const VERSION = "1.6.0-rc01";
|