Skip to content

Conversation

@GoldGroove06
Copy link
Contributor

@GoldGroove06 GoldGroove06 commented Apr 28, 2025

image

Summary by CodeRabbit

  • New Features
    • Introduced a new tab navigation component with accessible keyboard navigation and customizable orientation.
    • Added individual tab link elements with support for disabled state and custom styling.
  • Documentation
    • Added interactive Storybook stories for the new tab navigation component.
  • Style
    • Implemented new styles for tab navigation and tab links, including focus and hover states for improved usability.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 28, 2025

Walkthrough

A new tab navigation UI component system has been introduced. This includes a main TabNav component that serves as a namespace for two subcomponents: TabNav.Root and TabNav.Link. Supporting files provide context management, keyboard navigation, and styling. A Storybook story demonstrates the usage of these components, and new SCSS styles define their appearance. The styles are integrated into the main theme by updating the default SCSS import list.

Changes

Files/Paths Change Summary
src/components/ui/TabNav/TabNav.tsx Introduced TabNav wrapper component with Root and Link subcomponents, warns against direct usage.
src/components/ui/TabNav/context/TabNav.context.tsx Added TabNavContext React context with a rootClass property for context-based styling.
src/components/ui/TabNav/fragments/TabNavLink.tsx Added TabNavLink component for tab navigation links with context-based styling and focus management.
src/components/ui/TabNav/fragments/TabNavRoot.tsx Added TabNavRoot component as the container for tab navigation, providing context and focus management.
src/components/ui/TabNav/stories/TabNav.stories.tsx Added Storybook story for TabNav demonstrating usage with TabNav.Root and TabNav.Link components.
styles/themes/components/tab-nav.scss Added SCSS styles for .rad-ui-tab-nav and its child .rad-ui-tab-nav-link for layout and interactivity.
styles/themes/default.scss Imported new tab navigation styles into the default theme.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TabNav
    participant TabNavRoot
    participant TabNavLink
    participant TabNavContext

    User->>TabNav.Root: Render TabNav.Root
    TabNav.Root->>TabNavContext: Provide context (rootClass)
    TabNav.Root->>TabNavLink: Render children (TabNav.Link)
    TabNavLink->>TabNavContext: Consume context (rootClass)
    TabNavLink->>User: Render anchor element with styling and focus management
Loading

Possibly related PRs

Suggested reviewers

  • kotAPI

Poem

In the garden of code where new tabs bloom bright,
A Root and a Link now guide users’ sight.
With context and style, they hop into view,
And focus will rove as the rabbits pursue.
The SCSS is crisp, the stories are neat—
TabNav hops forward on nimble white feet!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (8)
styles/themes/components/tab-nav.scss (1)

1-23: Consider refactoring the CSS structure and using design tokens consistently.

The tab navigation styling is clean but has a few potential improvements:

  1. The hardcoded color #65636d should be replaced with a design token variable like your other color references
  2. The margin-left on links could cause inconsistent spacing with the container's gap
  3. The CSS nesting could be formatted more consistently

Consider this refactored version:

.rad-ui-tab-nav {
    display: flex;
    gap: 6px;

    .rad-ui-tab-nav-link {
        background-color: white;
-       color: #65636d;
+       color: var(--rad-ui-color-gray-600);
        display: flex;
        align-items: center;
        justify-content: center;
-       margin-left: 1px;

        &:focus-visible {
            outline: 2px solid var(--rad-ui-color-accent-900);
            outline-offset: 2px;
        }

        &:hover {
            background-color: var(--rad-ui-color-accent-300);
            color: var(--rad-ui-color-accent-950);
        }
    }
}
src/components/ui/TabNav/stories/TabNav.stories.tsx (4)

6-18: Storybook configuration looks good but consider enhancing the story structure.

The Storybook setup correctly demonstrates the TabNav component. However, consider following Storybook's latest practices by:

  1. Using the CSF 3.0 format with annotations
  2. Providing more descriptive story names rather than just "All"
  3. Moving the component from "WIP/" to a more appropriate category once it's ready
export default {
    title: 'WIP/TabNav',
    component: TabNav,
+   parameters: {
+     docs: {
+       description: {
+         component: 'TabNav component provides accessible tab navigation for the UI.'
+       }
+     }
+   },
    render: (args: React.JSX.IntrinsicAttributes) => <SandboxEditor>
        <div >
            <TabNav.Root>
                <TabNav.Link disabled href={'###'}>Tab 1</TabNav.Link>
                <TabNav.Link>Tab 2</TabNav.Link>
                <TabNav.Link>Tab 3</TabNav.Link>
            </TabNav.Root>
        </div>
    </SandboxEditor>
};

10-10: Remove unnecessary empty div wrapper or add purpose via className.

The empty div wrapper doesn't appear to serve any purpose. Either remove it or add a className that provides styling context.

- <div >
+ <div className="tabnav-container">

or

- <div >
-     <TabNav.Root>
+ <TabNav.Root>

12-12: Replace placeholder href value with a more semantic value.

The current placeholder href={'###'} isn't a valid URI. Consider using a more standard placeholder like # or omitting the href entirely for disabled links.

- <TabNav.Link disabled href={'###'}>Tab 1</TabNav.Link>
+ <TabNav.Link disabled href="#">Tab 1</TabNav.Link>

or

- <TabNav.Link disabled href={'###'}>Tab 1</TabNav.Link>
+ <TabNav.Link disabled>Tab 1</TabNav.Link>

20-24: Enhance the example story with arguments that demonstrate component functionality.

The current args only shows a text color class, which doesn't fully demonstrate the TabNav component's capabilities. Consider adding examples that show different orientations, disabled states, and active tabs.

export const All = {
    args: {
-       className: 'text-gray-950'
+       className: 'text-gray-950',
+       orientation: 'horizontal',
+       loop: true
    }
};

Then add additional stories:

export const Vertical = {
    args: {
        className: 'text-gray-950',
        orientation: 'vertical'
    },
    render: (args) => (
        <SandboxEditor>
            <TabNav.Root orientation="vertical">
                <TabNav.Link disabled>Tab 1</TabNav.Link>
                <TabNav.Link>Tab 2</TabNav.Link>
                <TabNav.Link>Tab 3</TabNav.Link>
            </TabNav.Root>
        </SandboxEditor>
    )
};
src/components/ui/TabNav/fragments/TabNavLink.tsx (2)

7-13: Complete the type definition with return type and additional accessibility props.

The TabNavLinkProps type should include common accessibility attributes for tabs and the return type for enhanced type safety.

export type TabNavLinkProps = {
    children: React.ReactNode,
    className?: string,
    href?: string,
    disabled?: boolean,
+   ariaLabel?: string,
+   ariaControls?: string,
+   active?: boolean,
+   onClick?: (e: React.MouseEvent<HTMLAnchorElement>) => void,
}

18-27: Consider implementing keyboard event handling for tab navigation.

The component relies on RovingFocusGroup for focus management but doesn't handle key events for tab selection (Enter/Space).

+ const handleKeyDown = (e: React.KeyboardEvent) => {
+   if (!disabled && (e.key === 'Enter' || e.key === ' ')) {
+     e.preventDefault();
+     onClick?.(e as unknown as React.MouseEvent<HTMLAnchorElement>);
+   }
+ };

return (
    <RovingFocusGroup.Item>
        <Primitive.a
            className={clsx(`${rootClass}-link`, className)}
            data-disabled={disabled}
            {...disabled ? {} : { href }}
+           onKeyDown={handleKeyDown}
        >
            {children}
        </Primitive.a>
    </RovingFocusGroup.Item>
);
src/components/ui/TabNav/fragments/TabNavRoot.tsx (1)

19-30: Consider adding auto-focus functionality for the selected tab.

The component currently doesn't provide auto-focus for the initially selected tab, which would improve keyboard navigation.

return (
    <TabNavContext.Provider
        value={{
            rootClass,
            selectedIndex,
            onSelect: handleTabSelect
        }}>
-       <RovingFocusGroup.Root loop={loop} orientation={orientation} >
+       <RovingFocusGroup.Root 
+           loop={loop} 
+           orientation={orientation}
+           defaultFocusedIndex={selectedIndex}
+       >
            <RovingFocusGroup.Group 
                className={clsx(rootClass, className)}
                role="tablist"
                aria-orientation={orientation}
                id={id}
            >
                {children}
            </RovingFocusGroup.Group>
        </RovingFocusGroup.Root>
    </TabNavContext.Provider>
);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 44d53e0 and 4b06b29.

📒 Files selected for processing (7)
  • src/components/ui/TabNav/TabNav.tsx (1 hunks)
  • src/components/ui/TabNav/context/TabNav.context.tsx (1 hunks)
  • src/components/ui/TabNav/fragments/TabNavLink.tsx (1 hunks)
  • src/components/ui/TabNav/fragments/TabNavRoot.tsx (1 hunks)
  • src/components/ui/TabNav/stories/TabNav.stories.tsx (1 hunks)
  • styles/themes/components/tab-nav.scss (1 hunks)
  • styles/themes/default.scss (1 hunks)
🧰 Additional context used
🪛 GitHub Check: lint
src/components/ui/TabNav/fragments/TabNavRoot.tsx

[warning] 1-1:
'Children' is defined but never used

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (3)
src/components/ui/TabNav/context/TabNav.context.tsx (1)

1-11: LGTM: Clean and well-structured React context implementation.

The TabNavContext is correctly implemented using React's createContext API with proper TypeScript typing. The context provides a rootClass property with a sensible default value of 'TabNav'.

A few minor points to consider:

  • The context export could be named (e.g., export default TabNavContext;export { TabNavContext }) to improve import consistency
  • Consider adding JSDoc comments to document the purpose of this context and interface
styles/themes/default.scss (1)

31-31: LGTM: Properly integrated the tab-nav styles into the theme.

The tab navigation styles have been correctly imported into the default theme, maintaining alphabetical organization within the component imports.

src/components/ui/TabNav/TabNav.tsx (1)

1-12: LGTM: Clean implementation of the composite component pattern.

The TabNav component follows React's composite component pattern correctly by exposing Root and Link subcomponents. The warning for direct usage is helpful for developers.

Comment on lines 15 to 29
const TabNavLink = ({ className = '', href = '#', children, disabled }: TabNavLinkProps) => {
const { rootClass } = useContext(TabNavContext);

return (
<RovingFocusGroup.Item>
<Primitive.a
className={clsx(`${rootClass}-link`, className)}
data-disabled={disabled}
{...disabled ? {} : { href }}
>
{children}
</Primitive.a>
</RovingFocusGroup.Item>
);
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance accessibility and add active state handling to the TabNavLink component.

The component needs improved accessibility for screen readers and keyboard users. It should also handle active state for tab selection.

- const TabNavLink = ({ className = '', href = '#', children, disabled }: TabNavLinkProps) => {
+ const TabNavLink = ({ 
+   className = '', 
+   href = '#', 
+   children, 
+   disabled, 
+   ariaLabel, 
+   ariaControls, 
+   active = false,
+   onClick 
+ }: TabNavLinkProps) => {
    const { rootClass } = useContext(TabNavContext);

    return (
        <RovingFocusGroup.Item>
            <Primitive.a
-               className={clsx(`${rootClass}-link`, className)}
+               className={clsx(`${rootClass}-link`, className, {
+                   [`${rootClass}-link--active`]: active
+               })}
                data-disabled={disabled}
+               aria-disabled={disabled}
+               aria-selected={active}
+               role="tab"
+               aria-label={ariaLabel}
+               aria-controls={ariaControls}
                {...disabled ? {} : { href }}
+               onClick={!disabled ? onClick : undefined}
            >
                {children}
            </Primitive.a>
        </RovingFocusGroup.Item>
    );
};

@@ -0,0 +1,34 @@
import React, { Children } from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove unused import 'Children' from React.

The static analysis correctly identified that the 'Children' import is not used in this file.

- import React, { Children } from 'react';
+ import React from 'react';
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import React, { Children } from 'react';
-import React, { Children } from 'react';
+import React from 'react';
🧰 Tools
🪛 GitHub Check: lint

[warning] 1-1:
'Children' is defined but never used

Comment on lines 9 to 15
export type TabNavRootProps = {
className?: string,
loop?: boolean,
orientation?: 'horizontal' | 'vertical',
children: React.ReactNode,
customRootClass?: string,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance the TabNavRootProps interface with selected tab management.

The current implementation doesn't handle the selected/active tab state. Consider adding props for controlling selected tab.

export type TabNavRootProps = {
    className?: string,
    loop?: boolean,
    orientation?: 'horizontal' | 'vertical',
    children: React.ReactNode,
    customRootClass?: string,
+   selectedIndex?: number,
+   onSelectionChange?: (index: number) => void,
+   id?: string,
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export type TabNavRootProps = {
className?: string,
loop?: boolean,
orientation?: 'horizontal' | 'vertical',
children: React.ReactNode,
customRootClass?: string,
}
export type TabNavRootProps = {
className?: string,
loop?: boolean,
orientation?: 'horizontal' | 'vertical',
children: React.ReactNode,
customRootClass?: string,
selectedIndex?: number,
onSelectionChange?: (index: number) => void,
id?: string,
}

Comment on lines 17 to 32
const TabNavRoot = ({ className, loop = true, orientation = 'horizontal', children, customRootClass = '', ...props }: TabNavRootProps) => {
const rootClass = customClassSwitcher(customRootClass, COMPONENT_NAME);
return (
<TabNavContext.Provider
value={{
rootClass
}}>
<RovingFocusGroup.Root loop={loop} orientation={orientation} >
<RovingFocusGroup.Group className={clsx(rootClass, className)}>
{children}
</RovingFocusGroup.Group>
</RovingFocusGroup.Root>
</TabNavContext.Provider>

);
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Implement selected tab state management and ARIA attributes for accessibility.

The current implementation lacks proper accessibility for tabs. Add ARIA roles and selected tab state management.

- const TabNavRoot = ({ className, loop = true, orientation = 'horizontal', children, customRootClass = '', ...props }: TabNavRootProps) => {
+ const TabNavRoot = ({ 
+   className, 
+   loop = true, 
+   orientation = 'horizontal', 
+   children, 
+   customRootClass = '', 
+   selectedIndex = 0,
+   onSelectionChange,
+   id,
+   ...props 
+ }: TabNavRootProps) => {
    const rootClass = customClassSwitcher(customRootClass, COMPONENT_NAME);
+   
+   const handleTabSelect = (index: number) => {
+     if (onSelectionChange) {
+       onSelectionChange(index);
+     }
+   };
+   
    return (
        <TabNavContext.Provider
            value={{
-               rootClass
+               rootClass,
+               selectedIndex,
+               onSelect: handleTabSelect
            }}>
            <RovingFocusGroup.Root loop={loop} orientation={orientation} >
-               <RovingFocusGroup.Group className={clsx(rootClass, className)}>
+               <RovingFocusGroup.Group 
+                   className={clsx(rootClass, className)}
+                   role="tablist"
+                   aria-orientation={orientation}
+                   id={id}
+               >
                    {children}
                </RovingFocusGroup.Group>
            </RovingFocusGroup.Root>
        </TabNavContext.Provider>
    );
};
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const TabNavRoot = ({ className, loop = true, orientation = 'horizontal', children, customRootClass = '', ...props }: TabNavRootProps) => {
const rootClass = customClassSwitcher(customRootClass, COMPONENT_NAME);
return (
<TabNavContext.Provider
value={{
rootClass
}}>
<RovingFocusGroup.Root loop={loop} orientation={orientation} >
<RovingFocusGroup.Group className={clsx(rootClass, className)}>
{children}
</RovingFocusGroup.Group>
</RovingFocusGroup.Root>
</TabNavContext.Provider>
);
};
const TabNavRoot = ({
className,
loop = true,
orientation = 'horizontal',
children,
customRootClass = '',
selectedIndex = 0,
onSelectionChange,
id,
...props
}: TabNavRootProps) => {
const rootClass = customClassSwitcher(customRootClass, COMPONENT_NAME);
const handleTabSelect = (index: number) => {
if (onSelectionChange) {
onSelectionChange(index);
}
};
return (
<TabNavContext.Provider
value={{
rootClass,
selectedIndex,
onSelect: handleTabSelect
}}
>
<RovingFocusGroup.Root loop={loop} orientation={orientation}>
<RovingFocusGroup.Group
className={clsx(rootClass, className)}
role="tablist"
aria-orientation={orientation}
id={id}
>
{children}
</RovingFocusGroup.Group>
</RovingFocusGroup.Root>
</TabNavContext.Provider>
);
};

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🔭 Outside diff range comments (1)
src/components/ui/TabNav/fragments/TabNavRoot.tsx (1)

1-40: 💡 Verification agent

🧩 Analysis chain

Verify TabNavContext updates are implemented in context file

To support the selection state management suggested above, the TabNavContext interface also needs to be updated.


🏁 Script executed:

#!/bin/bash
# Check if TabNavContext.tsx has the updated interface for selection state management

cat src/components/ui/TabNav/context/TabNav.context.tsx

Length of output: 264


TabNavContext: add selection state to context interface

The context currently only provides rootClass. To support controlled/uncontrolled tab selection (using useControllableState in TabNavRoot), update the context type and default value:

• File: src/components/ui/TabNav/context/TabNav.context.tsx

Suggested changes:

-import { createContext } from 'react';
+import { createContext } from 'react';

-interface TabNavContextType {
-    rootClass?: string;
-}
+interface TabNavContextType {
+    /** Styling hook from TabNavRoot */
+    rootClass?: string;
+    /** Currently selected tab key */
+    selectedKey: string;
+    /** Setter for selection state */
+    setSelectedKey: (key: string) => void;
+    /** Optional callback when selection changes */
+    onSelect?: (key: string) => void;
+}

-const TabNavContext = createContext<TabNavContextType>({
-    rootClass: ''
-});
+const TabNavContext = createContext<TabNavContextType>({
+    rootClass: '',
+    selectedKey: '',
+    setSelectedKey: () => {},
+    onSelect: undefined,
+});

 export default TabNavContext;

Then in TabNavRoot, use useControllableState to manage selectedKey/setSelectedKey and pass onSelect (if provided) into TabNavContext.Provider.

🧰 Tools
🪛 GitHub Check: lint

[warning] 6-6:
'useControllableState' is defined but never used


[warning] 1-1:
'useEffect' is defined but never used

♻️ Duplicate comments (4)
src/components/ui/TabNav/fragments/TabNavLink.tsx (2)

7-13: 🛠️ Refactor suggestion

Enhance TabNavLinkProps interface with accessibility properties

The current implementation lacks important accessibility props needed for proper tab navigation.

 export type TabNavLinkProps = {
     children: React.ReactNode,
     className?: string,
     href?: string,
     disabled?: boolean,
-    asChild?: boolean
+    asChild?: boolean,
+    ariaLabel?: string,
+    ariaControls?: string,
+    active?: boolean,
+    onClick?: (event: React.MouseEvent<HTMLAnchorElement>) => void
 }

15-33: ⚠️ Potential issue

Implement accessibility attributes and active state handling

The current implementation lacks proper accessibility attributes and state management for the tab navigation. It also has a TypeScript error that's being suppressed.

-const TabNavLink = ({ className = '', href = '#', children, disabled, asChild }: TabNavLinkProps) => {
+const TabNavLink = ({ 
+    className = '', 
+    href = '#', 
+    children, 
+    disabled, 
+    asChild,
+    ariaLabel,
+    ariaControls,
+    active = false,
+    onClick 
+}: TabNavLinkProps) => {
     const { rootClass } = useContext(TabNavContext);
     if (asChild) disabled = false;
 
     return (
         <RovingFocusGroup.Item >
             <Primitive.a
-                className={clsx(`${rootClass}-link`, className)}
+                className={clsx(`${rootClass}-link`, className, {
+                    [`${rootClass}-link--active`]: active
+                })}
                 asChild={asChild}
                 aria-disabled={disabled}
-                // @ts-expect-error
-                disabled={disabled}
+                aria-selected={active}
+                role="tab"
+                aria-label={ariaLabel}
+                aria-controls={ariaControls}
                 {...disabled ? {} : { href }}
+                onClick={!disabled ? onClick : undefined}
             >
                 {children}
             </Primitive.a>
         </RovingFocusGroup.Item>
     );
 };

This change:

  1. Adds proper ARIA attributes for tab accessibility
  2. Implements active state handling with visual indication
  3. Adds onClick handler that respects disabled state
  4. Removes the need for TypeScript error suppression
src/components/ui/TabNav/fragments/TabNavRoot.tsx (2)

10-17: 🛠️ Refactor suggestion

Enhance TabNavRootProps interface with selected tab management

The current implementation doesn't handle the selected/active tab state, which is essential for proper tab navigation.

 export type TabNavRootProps = {
     className?: string,
     loop?: boolean,
     orientation?: 'horizontal' | 'vertical',
     children: React.ReactNode,
     customRootClass?: string,
-    color?: string;
+    color?: string,
+    selectedIndex?: number,
+    onSelectionChange?: (index: number) => void,
+    id?: string,
 }

19-37: ⚠️ Potential issue

Implement selected tab state management and ARIA attributes for accessibility

The current implementation lacks proper accessibility for tabs and doesn't handle tab selection state properly. The color prop is also accepted but not used.

 const TabNavRoot = ({
-    className, loop = true, orientation = 'horizontal', children, color, customRootClass = '', ...props
+    className, 
+    loop = true, 
+    orientation = 'horizontal', 
+    children, 
+    customRootClass = '', 
+    selectedIndex = 0,
+    onSelectionChange,
+    id,
+    ...props
 }: TabNavRootProps) => {
     const rootClass = customClassSwitcher(customRootClass, COMPONENT_NAME);
-
-    const contextValues = {
-        rootClass
-    };
+    
+    const handleTabSelect = (index: number) => {
+        if (onSelectionChange) {
+            onSelectionChange(index);
+        }
+    };
+    
     return (
-        <TabNavContext.Provider value={contextValues}>
+        <TabNavContext.Provider value={{
+            rootClass,
+            selectedIndex,
+            onSelect: handleTabSelect
+        }}>
             <RovingFocusGroup.Root loop={loop} orientation={orientation} {...props} >
-                <RovingFocusGroup.Group className={clsx(rootClass, className)}>
+                <RovingFocusGroup.Group 
+                    className={clsx(rootClass, className)}
+                    role="tablist"
+                    aria-orientation={orientation}
+                    id={id}
+                >
                     {children}
                 </RovingFocusGroup.Group>
             </RovingFocusGroup.Root>
         </TabNavContext.Provider>
-
     );
 };

This change:

  1. Implements proper selection state management with callbacks
  2. Adds ARIA attributes for accessibility (role="tablist", aria-orientation)
  3. Removes the unused contextValues object in favor of inline context value
  4. Removes unused color prop
  5. Adds a unique ID for the tablist for better accessibility
🧹 Nitpick comments (4)
styles/themes/components/tab-nav.scss (1)

1-27: Fix indentation and formatting issues

The SCSS file has several formatting issues:

  1. Inconsistent indentation (some lines use 4 spaces, others 8)
  2. Missing space after the colon in height:42px
  3. Extra whitespace on line 25
 .rad-ui-tab-nav{
     display: flex;
-        box-shadow: inset 0 -1px 0 0 var(--rad-ui-color-gray-500);
+     box-shadow: inset 0 -1px 0 0 var(--rad-ui-color-gray-500);
 
     .rad-ui-tab-nav-link {
         color: var(--rad-ui-color-accent-600);
-            font-family: inherit;
-            padding: 10px;
-            display: flex;
-            align-items: center;
-            height:42px;
-            font-size: 15px;
-            line-height: 1;
-            cursor: pointer;
+         font-family: inherit;
+         padding: 10px;
+         display: flex;
+         align-items: center;
+         height: 42px;
+         font-size: 15px;
+         line-height: 1;
+         cursor: pointer;
 
             &[aria-selected="true"]{
                 color: var(--rad-ui-color-accent-950);
                 border-bottom:2px solid var(--rad-ui-color-accent-900);
             }
 
             &:hover{
                 color: var(--rad-ui-color-accent-900);
             }
-
-       
+      
 }
 }
src/components/ui/TabNav/fragments/TabNavLink.tsx (1)

1-1: Remove unused import

The useRef import is defined but never used in this component.

- import React, { useContext, useRef } from 'react';
+ import React, { useContext } from 'react';
🧰 Tools
🪛 GitHub Check: lint

[warning] 1-1:
'useRef' is defined but never used

src/components/ui/TabNav/fragments/TabNavRoot.tsx (2)

1-1: Remove unused import

The useEffect import is defined but never used in this component.

- import React, { useEffect } from 'react';
+ import React from 'react';
🧰 Tools
🪛 GitHub Check: lint

[warning] 1-1:
'useEffect' is defined but never used


6-6: Remove unused import

The useControllableState hook is imported but never used in this component.

- import useControllableState from '~/core/hooks/useControllableState';
🧰 Tools
🪛 GitHub Check: lint

[warning] 6-6:
'useControllableState' is defined but never used

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4b06b29 and 25ac84c.

📒 Files selected for processing (4)
  • src/components/ui/TabNav/context/TabNav.context.tsx (1 hunks)
  • src/components/ui/TabNav/fragments/TabNavLink.tsx (1 hunks)
  • src/components/ui/TabNav/fragments/TabNavRoot.tsx (1 hunks)
  • styles/themes/components/tab-nav.scss (1 hunks)
🧰 Additional context used
🪛 GitHub Check: lint
src/components/ui/TabNav/fragments/TabNavLink.tsx

[warning] 1-1:
'useRef' is defined but never used

src/components/ui/TabNav/fragments/TabNavRoot.tsx

[warning] 6-6:
'useControllableState' is defined but never used


[warning] 1-1:
'useEffect' is defined but never used

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (1)
src/components/ui/TabNav/context/TabNav.context.tsx (1)

1-11: LGTM! Context implementation is clean and follows best practices

The TabNav context is implemented correctly with a well-defined TypeScript interface and proper default value.

@kotAPI kotAPI added the automerge A tag that tells kodiak bot to automerge PRs for us when tests and approval conditions are met label Apr 29, 2025
@kodiakhq kodiakhq bot merged commit ba4f361 into rad-ui:main Apr 29, 2025
4 checks passed
@coderabbitai coderabbitai bot mentioned this pull request May 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge A tag that tells kodiak bot to automerge PRs for us when tests and approval conditions are met

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants