Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/solid-link-role.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/solid-router': patch
---

Preserve caller-provided roles on enabled links.
2 changes: 1 addition & 1 deletion packages/solid-router/src/link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ export function useLinkProps<
href: () => hrefOption()?.href,
disabled: () => !!local.disabled,
target: () => local.target,
role: () => (local.disabled ? 'link' : undefined),
role: () => (local.disabled ? 'link' : propsSafeToSpread.role),
'aria-disabled': () => (local.disabled ? 'true' : undefined),
'data-status': () => (isActive() ? 'active' : undefined),
'aria-current': () => (isActive() ? 'page' : undefined),
Expand Down
45 changes: 45 additions & 0 deletions packages/solid-router/tests/link.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,51 @@ describe('Link', () => {
).rejects.toThrow()
})

test('preserves a caller-provided role while enabled', async () => {
const [disabled, setDisabled] = Solid.createSignal(false)
const rootRoute = createRootRoute()
const indexRoute = createRoute({
getParentRoute: () => rootRoute,
path: '/',
component: () => (
<>
<button onClick={() => setDisabled((value) => !value)}>
Toggle disabled
</button>
<Link
data-testid="role-link"
to="/posts"
role="button"
disabled={disabled()}
>
Posts
</Link>
</>
),
})
const postsRoute = createRoute({
getParentRoute: () => rootRoute,
path: '/posts',
})
const router = createRouter({
routeTree: rootRoute.addChildren([indexRoute, postsRoute]),
history,
})

render(() => <RouterProvider router={router} />)

const link = await screen.findByTestId('role-link')
const toggle = screen.getByRole('button', { name: 'Toggle disabled' })

expect(link).toHaveAttribute('role', 'button')

fireEvent.click(toggle)
await waitFor(() => expect(link).toHaveAttribute('role', 'link'))

fireEvent.click(toggle)
await waitFor(() => expect(link).toHaveAttribute('role', 'button'))
})

test('does not forward internal Link props to the DOM', async () => {
const internalPropNames = [
'activeProps',
Expand Down