Skip to content

Commit e581fe7

Browse files
committed
Added NavigationCurrentEntryChangeEvent interface and addEventListener/removeEventListener methods to the POS Navigation API
1 parent 5fe24b3 commit e581fe7

File tree

1 file changed

+28
-0
lines changed
  • packages/ui-extensions/src/surfaces/point-of-sale/api/navigation-api

1 file changed

+28
-0
lines changed

packages/ui-extensions/src/surfaces/point-of-sale/api/navigation-api/navigation-api.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ export interface NavigationHistoryEntry {
2626
getState(): unknown;
2727
}
2828

29+
/**
30+
* The event object for the `currententrychange` event, which fires when `Navigation.currentEntry` has changed due to navigation within the extension modal. Use to access information about the previous navigation entry when responding to navigation changes.
31+
*/
32+
export interface NavigationCurrentEntryChangeEvent {
33+
/**
34+
* The `NavigationHistoryEntry` that was navigated away from. Use to access the previous URL, key, or state when tracking navigation transitions or implementing breadcrumb-style navigation.
35+
*/
36+
from: NavigationHistoryEntry;
37+
}
38+
2939
export interface Navigation {
3040
/**
3141
* Navigates to a specific URL, updating any provided state in the history entries list. Returns a promise that resolves when navigation is complete. Use for programmatic navigation between screens, implementing custom navigation controls, or deep-linking to specific modal states.
@@ -39,6 +49,24 @@ export interface Navigation {
3949
* Navigates to the previous entry in the history list. Use for implementing back buttons, breadcrumb navigation, or allowing users to return to previous screens in multi-step workflows.
4050
*/
4151
back(): void;
52+
/**
53+
* Registers an event listener for navigation events. The `currententrychange` event fires when the `currentEntry` property changes, such as when the user navigates to a different screen within the extension modal. Use to track navigation changes, update UI state based on the current location, or implement analytics for navigation patterns.
54+
* @param type - The event type to listen for. Currently only `'currententrychange'` is supported.
55+
* @param cb - The callback function invoked when the event fires. Receives a `NavigationCurrentEntryChangeEvent` containing the previous entry that was navigated away from.
56+
*/
57+
addEventListener(
58+
type: 'currententrychange',
59+
cb: (event: NavigationCurrentEntryChangeEvent) => void,
60+
): void;
61+
/**
62+
* Removes a previously registered event listener. The callback reference must match the one passed to `addEventListener`. Use to clean up event listeners when they are no longer needed, such as when a component unmounts or navigation tracking should be disabled.
63+
* @param type - The event type to remove the listener for. Currently only `'currententrychange'` is supported.
64+
* @param cb - The callback function to remove. Must be the same function reference that was passed to `addEventListener`.
65+
*/
66+
removeEventListener(
67+
type: 'currententrychange',
68+
cb: (event: NavigationCurrentEntryChangeEvent) => void,
69+
): void;
4270
}
4371

4472
/**

0 commit comments

Comments
 (0)