Skip to content

Commit 6456a64

Browse files
committed
Implement useId and make id prop optional again
1 parent 2aa638d commit 6456a64

5 files changed

Lines changed: 11 additions & 5 deletions

File tree

packages/skeleton-react/src/lib/components/Navigation/Navigation.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import React, { createContext, useContext } from 'react';
3+
import React, { createContext, useContext, useId } from 'react';
44
import { NavContextState, NavRailProps, NavBarProps, NavTileProps } from './types.js';
55

66
// Contexts ---
@@ -187,6 +187,11 @@ export const NavTile: React.FC<NavTileProps> = ({
187187
// Get Context
188188
const ctx = useContext<NavContextState>(NavContext);
189189

190+
const generatedId = useId();
191+
if(!id) {
192+
id = generatedId;
193+
}
194+
190195
// Local
191196
const TileElement = href ? 'a' : 'button';
192197
const role = href ? undefined : 'button';

packages/skeleton-react/src/lib/components/Navigation/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export interface NavRailProps extends NavCommonProps {
9797

9898
export interface NavTileProps {
9999
/** Provide a unique ID. */
100-
id: string;
100+
id?: string;
101101
/** Provide an href link; turns Tiles into an anchor */
102102
href?: string;
103103
/** Set the href target attribute. */

packages/skeleton-svelte/src/lib/components/Navigation/NavTile.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<script lang="ts">
2+
import { useId } from '$lib/internal/use-id.js';
23
import { getNavigationContext } from './context.js';
34
import type { NavTileProps } from './types.js';
45
56
let {
6-
id,
7+
id = useId(),
78
href,
89
target,
910
label,

packages/skeleton-svelte/src/lib/components/Navigation/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export interface NavRailProps extends NavCommonProps {
9999

100100
export interface NavTileProps {
101101
/** Provide a unique ID. */
102-
id: string;
102+
id?: string;
103103
/** Provide an href link; turns Tiles into an anchor */
104104
href?: string;
105105
/** Set the href target attribute. */

packages/skeleton-svelte/src/lib/components/Toast/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export interface Toast {
3030
// Context ---
3131

3232
// https://zagjs.com/components/react/toast#programmatic-control
33-
/** Provides accesss to the Toast Context API. */
33+
/** Provides access to the Toast Context API. */
3434
export interface ToastContext {
3535
/** Used to create display a new Toast instance. */
3636
create: (toast: Toast) => void;

0 commit comments

Comments
 (0)