Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(suite): Add orientation for SelectBar component #16844

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

jvaclavik
Copy link
Contributor

Description

Related Issue

Resolve

Screenshots:

Screenshot 2025-02-05 at 14 29 16

@jvaclavik jvaclavik requested a review from a team as a code owner February 5, 2025 13:29
Copy link

coderabbitai bot commented Feb 5, 2025

Walkthrough

The pull request implements support for orientation customization in the SelectBar component. It introduces a new orientation prop that accepts specific values ("horizontal", "vertical", or "auto") and defaults to "auto" via the DEFAULT_ORIENTATION constant. In the component file, styled elements such as the wrapper, options, and puck have been updated to adjust their layout and styling based on this new property. Additionally, new constants (orientations, DEFAULT_ORIENTATION) and a type (Orientation) have been defined alongside an update to the component’s props to include the orientation field. Similarly, the Storybook configuration has been modified to include a control for the orientation prop, using radio buttons populated with the valid orientation options.

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.

🪧 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. (Beta)
  • @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

@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 (2)
packages/components/src/components/form/SelectBar/SelectBar.tsx (2)

256-282: Add keyboard navigation support for vertical orientation.

The keyboard navigation should handle both horizontal and vertical orientations:

 const handleKeyboardNav = (e: KeyboardEvent) => {
     const selectedOptionIndex = options.findIndex(option => option.value === selectedOptionIn);
 
     let option;
-    if (e.key === 'ArrowLeft') {
+    if (e.key === 'ArrowLeft' || (orientation === 'vertical' && e.key === 'ArrowUp')) {
         const previousIndex = selectedOptionIndex - 1;
 
         if (previousIndex >= 0) {
             option = options[previousIndex];
         } else {
             option = options[options.length - 1];
         }
-    } else if (e.key === 'ArrowRight') {
+    } else if (e.key === 'ArrowRight' || (orientation === 'vertical' && e.key === 'ArrowDown')) {
         const previousIndex = selectedOptionIndex + 1;
 
         if (previousIndex <= options.length - 1) {
             option = options[previousIndex];
         } else {
             [option] = options;
         }
     }

296-309: Add ARIA attributes for better accessibility.

The component should include proper ARIA attributes to improve accessibility for screen readers:

 <Options
     $optionsCount={options.length}
     $isFullWidth={isFullWidth}
     $elevation={elevation}
     $orientation={orientation}
+    role="radiogroup"
+    aria-orientation={orientation === 'vertical' ? 'vertical' : 'horizontal'}
 >
     <Puck
         $optionsCount={options.length}
         $selectedIndex={selectedIndex}
         $elevation={nextElevation[elevation]}
         $orientation={orientation}
         tabIndex={0}
         onKeyDown={handleKeyboardNav}
+        aria-hidden="true"
     />

Also add ARIA attributes to the Option component:

 <Option
     key={String(option.value)}
     onClick={handleOptionClick(option)}
     $isDisabled={!!isDisabled}
     $isSelected={selectedOptionIn !== undefined ? selectedOptionIn === option.value : false}
     data-testid={`select-bar/${String(option.value)}`}
+    role="radio"
+    aria-checked={selectedOptionIn === option.value}
+    aria-disabled={isDisabled}
 >
🧹 Nitpick comments (3)
packages/components/src/components/form/SelectBar/SelectBar.tsx (3)

29-32: Add JSDoc comments for better documentation.

Consider adding JSDoc comments to explain the purpose and usage of these exported constants and types.

+/** Valid orientation values for the SelectBar component */
 export const orientations = ['horizontal', 'vertical', 'auto'] as const;
+/** Type representing the possible orientation values */
 export type Orientation = (typeof orientations)[number];
+/** Default orientation value for the SelectBar component */
 export const DEFAULT_ORIENTATION = 'auto';

47-71: Simplify columnPuck implementation and add comments.

The CSS helpers could be improved for better maintainability:

+// Styles for vertical orientation wrapper
 const columnWrapper = css`
     flex-direction: column;
     align-items: flex-start;
     width: 100%;
 `;

+// Styles for vertical orientation options container
 const columnOption = css`
     grid-auto-flow: row;
     width: 100%;
     border-radius: ${borders.radii.lg};
 `;

-const columnPuck = ({
-    $selectedIndex: selectedIndex,
-    $optionsCount,
-}: {
-    $optionsCount: number;
-    $selectedIndex: number;
-}) => css`
+// Styles for vertical orientation puck
+const columnPuck = css<{ $optionsCount: number; $selectedIndex: number }>`
     left: 4px;
     right: 4px;
     top: 4px;
     width: auto;
-    height: ${getPuckWidth($optionsCount)};
-    transform: ${`translateY(${getTranslateValue(selectedIndex)})`};
+    height: ${({ $optionsCount }) => getPuckWidth($optionsCount)};
+    transform: ${({ $selectedIndex }) => `translateY(${getTranslateValue($selectedIndex)})`};
 `;

72-157: Extract media queries and simplify vertical styles.

The styled components could be improved for better maintainability and reusability:

+const belowSmBreakpoint = css`
+  ${breakpointMediaQueries.below_sm} {
+    ${columnWrapper}
+  }
+`;

 const Wrapper = styled.div<
     TransientProps<AllowedFrameProps> & { $isFullWidth?: boolean; $orientation: Orientation }
 >`
     /* ... existing styles ... */

     ${({ $orientation }) =>
-        $orientation === 'auto' &&
-        css`
-            ${breakpointMediaQueries.below_sm} {
-                ${columnWrapper}
-            }
-        `}
+        $orientation === 'auto' && belowSmBreakpoint}

     ${({ $orientation }) => $orientation === 'vertical' && columnWrapper}
 `;

 /* Apply similar changes to Options and Puck components */
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c89c834 and fcfe301.

📒 Files selected for processing (2)
  • packages/components/src/components/form/SelectBar/SelectBar.stories.tsx (3 hunks)
  • packages/components/src/components/form/SelectBar/SelectBar.tsx (8 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: run-desktop-tests (@group=wallet, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: run-desktop-tests (@group=settings, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: run-desktop-tests (@group=device-management, trezor-user-env-unix)
  • GitHub Check: Setup and Cache Dependencies
  • GitHub Check: build-web
  • GitHub Check: build-web
  • GitHub Check: run-desktop-tests (@group=suite, trezor-user-env-unix)
  • GitHub Check: Analyze with CodeQL (javascript)
🔇 Additional comments (1)
packages/components/src/components/form/SelectBar/SelectBar.stories.tsx (1)

4-9: LGTM! Well-structured Storybook configuration.

The orientation control is properly implemented with appropriate defaults and radio button selection.

Also applies to: 26-26, 59-64

Comment on lines +80 to +88
${({ $orientation }) =>
$orientation === 'auto' &&
css`
${breakpointMediaQueries.below_sm} {
${columnWrapper}
}
`}

${({ $orientation }) => $orientation === 'vertical' && columnWrapper}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not 100% happy with this, if you have better idea how to do it, feel free to comment it

@jvaclavik jvaclavik requested a review from enjojoy February 6, 2025 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🏃‍♀️ In progress
Development

Successfully merging this pull request may close these issues.

1 participant