Skip to content

Reusable Fluent UI v9 Toast control for SPFx solutions - #2131

Open
HarminderSethi wants to merge 1 commit into
pnp:devfrom
HarminderSethi:dev
Open

Reusable Fluent UI v9 Toast control for SPFx solutions#2131
HarminderSethi wants to merge 1 commit into
pnp:devfrom
HarminderSethi:dev

Conversation

@HarminderSethi

Copy link
Copy Markdown
Contributor
Q A
Bug fix? [ ]
New feature? [x]
New sample? [ ]
Related issues? N/A

What's in this Pull Request?

A reusable Fluent UI v9 Toast control for SPFx solutions. It removes the need for consumers to manually configure FluentProvider, Toaster, controller IDs, dispatch logic, and notification lifecycle behavior.

Features
Zero-configuration declarative
Shared ToastProvider and useToast() API
Native queueing, stacking, limits, and positioning
Intent icons and accessible live-region behavior
Auto-dismiss, pause, resume, and manual dismissal
Custom themes, content, actions, styles, and portal targets
Controls Test integration and documentation

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

There is a confirmed timeout default bug when durationUnit="seconds" is set without duration, and the Controls Test toggle list is missing controls that are rendered/typed, preventing them from being enabled individually.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR introduces a reusable Fluent UI v9 Toast control for SPFx consumers, aiming to provide a zero-configuration declarative <Toast /> experience plus a shared ToastProvider/useToast() API, and wires it into the Controls Test harness and documentation.

Changes:

  • Added new Toast control implementation (Toast, ToastProvider, useToast) with Fluent UI v9 Toaster integration.
  • Exported the control through the public package surface (src/Toast.ts, src/index.ts).
  • Added Controls Test + documentation integration (visibility toggles, manifest defaults, mkdocs nav, new Toast docs page).
File summaries
File Description
src/webparts/controlsTest/propertyPane/controls/ControlToggles.tsx Adds Toast to the property-pane control toggles list (and should include other missing toggles).
src/webparts/controlsTest/IControlsTestWebPartProps.ts Extends ValidControls union to include Toast.
src/webparts/controlsTest/ControlsTestWebPart.manifest.json Adds Toast default visibility flag.
src/webparts/controlsTest/components/ControlsTest.tsx Lazy-loads and renders a sample Toast section in Controls Test.
src/Toast.ts Public entrypoint re-export for the toast control bundle.
src/index.ts Exposes Toast from the main library index.
src/controls/toast/useToast.ts Adds useToast() hook for imperative dispatch via a shared provider.
src/controls/toast/ToastProvider.tsx Implements provider/controller wiring, dispatch logic, and timeout calculation.
src/controls/toast/Toast.tsx Implements declarative <Toast /> that dispatches on mount and auto-wraps in a provider when needed.
src/controls/toast/IToast.ts Defines Toast props/options/provider/controller public types.
src/controls/toast/index.ts Barrel exports and Fluent UI re-exports for toast-related primitives/types.
docs/documentation/mkdocs.yml Adds Toast page to mkdocs navigation.
docs/documentation/docs/index.md Lists Toast in the documentation index.
docs/documentation/docs/controls/Toast.md Adds end-user documentation for Toast/ToastProvider/useToast usage and API surface.
Review details
  • Files reviewed: 14/14 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +44 to +45
const duration = options.duration ?? DEFAULT_DURATION_MS;
return options.durationUnit === 'seconds' ? duration * 1000 : duration;
Comment on lines 69 to 72
"TaxonomyPicker", "TaxonomyTree", "Teams", "TermSetNavigation",
"TestControl", "Toolbar", "TreeView",
"TestControl", "Toolbar", "Toast", "TreeView",
"UploadFiles", "UserPicker", "VariantThemeProvider",
"ViewPicker", "WebPartTitle", "Calendar"
Comment on lines +39 to +46
const getTimeout = (options: IShowToastOptions): number => {
if (!options.autoDismiss) {
return -1;
}

const duration = options.duration ?? DEFAULT_DURATION_MS;
return options.durationUnit === 'seconds' ? duration * 1000 : duration;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants