@estiva-app/ui 0.60.1 → 0.60.2
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/dist/AppProvider.d.ts +3 -2
- package/dist/AppProvider.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
- package/registry.json +1 -1
- package/src/AppProvider.mdx +3 -1
- package/src/AppProvider.test.tsx +7 -0
- package/src/AppProvider.tsx +6 -3
package/package.json
CHANGED
package/registry.json
CHANGED
package/src/AppProvider.mdx
CHANGED
|
@@ -54,7 +54,9 @@ function Root({ children }) {
|
|
|
54
54
|
did, which is also what a story or a test sees without one.
|
|
55
55
|
- `pictureFor` gets the person's name and returns an address, or nothing for
|
|
56
56
|
the initials.
|
|
57
|
-
- `navigate` gets the link's
|
|
57
|
+
- `navigate` gets the link's path, query and `#` part (`/message/1?x=2`),
|
|
58
|
+
also when the `href` is the app's whole address (`https://app.test/message/1`):
|
|
59
|
+
a router reads a whole address as a path under the current page. The browser keeps
|
|
58
60
|
every other click: one already handled (`preventDefault`), one with Ctrl,
|
|
59
61
|
Cmd, Shift or Alt, the middle button, a link that opens a new tab or
|
|
60
62
|
downloads, and an address on another site or in another scheme
|
package/src/AppProvider.test.tsx
CHANGED
|
@@ -86,6 +86,13 @@ describe('changing page', () => {
|
|
|
86
86
|
expect(navigate).toHaveBeenCalledWith('/topics')
|
|
87
87
|
})
|
|
88
88
|
|
|
89
|
+
it("hands over the path when the href is the app's whole address", async () => {
|
|
90
|
+
const navigate = vi.fn()
|
|
91
|
+
inApp(navigate, <Link href={`${window.location.origin}/message/1?thread=2#r3`}>Message</Link>)
|
|
92
|
+
await userEvent.click(screen.getByRole('link'))
|
|
93
|
+
expect(navigate).toHaveBeenCalledWith('/message/1?thread=2#r3')
|
|
94
|
+
})
|
|
95
|
+
|
|
89
96
|
it("runs the caller's own onClick first", async () => {
|
|
90
97
|
const order: string[] = []
|
|
91
98
|
inApp(() => order.push('navigate'), <Link href="/topics" onClick={() => order.push('caller')}>Topics</Link>)
|
package/src/AppProvider.tsx
CHANGED
|
@@ -10,8 +10,9 @@ export interface AppProviderProps {
|
|
|
10
10
|
pictureFor?: (name: string) => string | null | undefined
|
|
11
11
|
/**
|
|
12
12
|
* How this app changes page without reloading. A plain click on a link to
|
|
13
|
-
* this app's own address calls it with the link's
|
|
14
|
-
* the
|
|
13
|
+
* this app's own address calls it with the link's path (`/message/1`, also
|
|
14
|
+
* when the `href` is the whole `https://…` address) instead of loading the
|
|
15
|
+
* page again: `Link` (and so `Card` and `Breadcrumb`'s crumbs),
|
|
15
16
|
* `NavItem` (and so `NavTree`'s rows), `RailItem`, `Chip`, `InlineChip`, and
|
|
16
17
|
* `IconButton` (and so `ToolbarLink`).
|
|
17
18
|
*/
|
|
@@ -71,6 +72,8 @@ export function useInAppClick<E extends HTMLElement>(href: string | undefined, o
|
|
|
71
72
|
}
|
|
72
73
|
if (url.origin !== window.location.origin) return
|
|
73
74
|
event.preventDefault()
|
|
74
|
-
|
|
75
|
+
// The path, never the whole address: a router reads `https://…` as a path
|
|
76
|
+
// under the current page and lands nowhere (Peek's message link, 8 October).
|
|
77
|
+
navigate(`${url.pathname}${url.search}${url.hash}`)
|
|
75
78
|
}
|
|
76
79
|
}
|