diff --git a/.changeset/eleven-pens-guess.md b/.changeset/eleven-pens-guess.md new file mode 100644 index 000000000..9d07a6fe1 --- /dev/null +++ b/.changeset/eleven-pens-guess.md @@ -0,0 +1,7 @@ +--- +'@saas-ui/theme': patch +'@saas-ui/core': patch +'@saas-ui/react': patch +--- + +NavItem now renders an aria-current tag when the item is active. diff --git a/.changeset/strong-bottles-rhyme.md b/.changeset/strong-bottles-rhyme.md new file mode 100644 index 000000000..9ecb86670 --- /dev/null +++ b/.changeset/strong-bottles-rhyme.md @@ -0,0 +1,6 @@ +--- +'@saas-ui/theme': patch +'@saas-ui/react': patch +--- + +NavItem active state is now compatible with Remix and ReactRouter NavLink diff --git a/packages/saas-ui-core/src/sidebar/nav-item.tsx b/packages/saas-ui-core/src/sidebar/nav-item.tsx index 1adaa09ab..8d3575d64 100644 --- a/packages/saas-ui-core/src/sidebar/nav-item.tsx +++ b/packages/saas-ui-core/src/sidebar/nav-item.tsx @@ -134,6 +134,7 @@ export const NavItem = forwardRef((props, ref) => { const link = ( - Home + Home Users Settings @@ -82,7 +82,7 @@ WithLinks.args = { children: ( <> - Home + Home Users Settings @@ -95,7 +95,9 @@ WithFeatherIcons.args = { children: ( <> - }>Home + } isActive> + Home + }>Users }>Settings @@ -108,7 +110,9 @@ WithFaIcons.args = { children: ( <> - }>Home + } isActive> + Home + }>Users }>Settings @@ -133,7 +137,9 @@ WithHorizontalNav.args = { - }>Home + } isActive> + Home + }>Users }>Settings diff --git a/packages/saas-ui-theme/src/base/components/nav-item.ts b/packages/saas-ui-theme/src/base/components/nav-item.ts index a30c62181..67fdf871f 100644 --- a/packages/saas-ui-theme/src/base/components/nav-item.ts +++ b/packages/saas-ui-theme/src/base/components/nav-item.ts @@ -58,7 +58,15 @@ const baseStyle = definePartsStyle((props) => { } }) +// &[aria-current=page] styles are used for ReactRouter and Remix NavLink components + const variantNeutral = definePartsStyle((props) => { + const _active = { + bg: 'blackAlpha.200', + _dark: { + bg: `whiteAlpha.300`, + }, + } return { link: { _hover: { @@ -67,12 +75,8 @@ const variantNeutral = definePartsStyle((props) => { bg: `whiteAlpha.200`, }, }, - _active: { - bg: 'blackAlpha.200', - _dark: { - bg: `whiteAlpha.300`, - }, - }, + _active, + ['&[aria-current=page]']: _active, }, icon: { opacity: 0.8, @@ -86,6 +90,16 @@ const variantNeutral = definePartsStyle((props) => { const variantSubtle = definePartsStyle((props) => { const { colorScheme: c, theme } = props + const _active = { + bg: transparentize(`${c}.500`, 0.3)(theme), + fontWeight: 'semibold', + color: `${c}.600`, + _dark: { + bg: transparentize(`${c}.500`, 0.3)(theme), + color: `${c}.100`, + }, + } + return { link: { _hover: { @@ -94,22 +108,17 @@ const variantSubtle = definePartsStyle((props) => { bg: `whiteAlpha.200`, }, }, - _active: { - bg: transparentize(`${c}.500`, 0.3)(theme), - fontWeight: 'semibold', - color: `${c}.600`, - _dark: { - bg: transparentize(`${c}.500`, 0.3)(theme), - color: `${c}.100`, - }, - }, + _active, + ['&[aria-current=page]']: _active, }, } }) const variantSolid = definePartsStyle((props) => { const { colorScheme: c } = props - + const _active = { + bg: `${c}.500`, + } return { link: { _hover: { @@ -118,9 +127,8 @@ const variantSolid = definePartsStyle((props) => { bg: `whiteAlpha.200`, }, }, - _active: { - bg: `${c}.500`, - }, + _active, + ['&[aria-current=page]']: _active, color: 'white', }, icon: {