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

Improved input layout to support proper positioning for right-to-left languages #322

Merged
merged 2 commits into from
Jan 9, 2025

Conversation

andreyjamer
Copy link
Contributor

@andreyjamer andreyjamer commented Sep 6, 2024

Current FwbInput implementation uses position: absolute for prefix and suffix. It causes some issues with positioning for dir="rtl" case.
This is how the input with prefix and suffix looks like in this case:
image

My idea is to switch from using absolute position to just display: flex for the input wrapper. This will enable the direction management out of the box and will simplify component sizes and positions management.

This is how result looks like:
image

The next step with this implementation could be improvements for different sizes of the input. Now only size="lg" looks good with button as suffix

Summary by CodeRabbit

  • New Features

    • Added multiple sizes for the <fwb-input> component, enhancing versatility with different suffix button sizes.
    • Improved layout and styling of the input fields for better visual alignment and responsiveness.
  • Bug Fixes

    • Adjusted prefix and suffix slots to maintain size consistency regardless of input field width.
  • Refactor

    • Simplified and modularized styling logic for input elements, improving clarity and maintainability.

Copy link
Contributor

coderabbitai bot commented Sep 6, 2024

Walkthrough

The changes involve the addition of multiple instances of the <fwb-input> component within a Vue file, replacing a single instance with three new ones of varying sizes. The layout and styling of the FwbInput component have been updated to enhance responsiveness, utilizing flexbox for alignment. Additionally, the useInputClasses function has been modified to improve styling logic, introducing new constants and computed properties for better management of input classes.

Changes

Files Change Summary
docs/components/input/examples/FwbInputExampleSuffix.vue Added multiple <fwb-input> instances with varying sizes and updated suffix buttons accordingly.
src/components/FwbInput/FwbInput.vue Enhanced layout with items-center class; adjusted prefix/suffix slots; updated inputBlockClasses.
src/components/FwbInput/composables/useInputClasses.ts Introduced defaultBlockClasses; updated successInputClasses and errorInputClasses; added new computed property inputBlockClasses.

Possibly related PRs

  • feat: FwbInput: Split input and block classes #325: The changes in this PR involve modifications to the <fwb-input> component, which is directly related to the main PR's updates that add multiple instances of this component with varying attributes. Both PRs focus on enhancing the flexibility and usability of the <fwb-input> component.

Suggested reviewers

  • Sqrcz

Poem

🐰 In a field where inputs play,
A new design has come to stay.
With classes neat and centers bright,
Our forms now dance with pure delight!
So hop along, let’s celebrate,
For style and grace, we elevate! 🎉

Finishing Touches

  • 📝 Generate Docstrings

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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. (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

netlify bot commented Sep 6, 2024

Deploy Preview for sensational-seahorse-8635f8 ready!

Name Link
🔨 Latest commit 84fc746
🔍 Latest deploy log https://app.netlify.com/sites/sensational-seahorse-8635f8/deploys/677f966ae6fb5c00085097c2
😎 Deploy Preview https://deploy-preview-322--sensational-seahorse-8635f8.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c679aa9 and 62fb704.

Files selected for processing (2)
  • src/components/FwbInput/FwbInput.vue (3 hunks)
  • src/components/FwbInput/composables/useInputClasses.ts (4 hunks)
Additional comments not posted (7)
src/components/FwbInput/FwbInput.vue (4)

7-10: Improved layout and responsiveness.

The addition of flex and items-center classes along with the dynamic inputBlockClasses significantly enhances the alignment and responsiveness of the component, especially for RTL languages.


13-13: Consistent sizing for prefix element.

The addition of flex-shrink-0 ensures that the prefix element maintains its size, contributing to a more consistent layout across varying screen sizes and input contents.


28-28: Proper alignment and spacing for suffix element.

The addition of flex-shrink-0 and me-3 ensures that the suffix element maintains its size and proper spacing, which is crucial for layout consistency and alignment, particularly in RTL configurations.


85-85: Expanded styling logic.

The inclusion of inputBlockClasses in the destructuring of useInputClasses reflects an expansion in the component's styling logic, likely to better accommodate RTL languages and various input sizes.

src/components/FwbInput/composables/useInputClasses.ts (3)

13-18: Enhanced styling flexibility and consistency.

The simplification of defaultInputClasses and the introduction of defaultBlockClasses enhance the flexibility and consistency of the input's appearance, particularly when focused. These changes are likely part of the efforts to improve layout handling for RTL languages.


Line range hint 40-50: Improved modularity and clarity in styling logic.

The introduction of the inputBlockClasses computed property allows for more granular control over the styling of block-level input elements, enhancing the modularity and clarity of the styling logic.


56-58: Continued flexibility in customizing input appearance.

The adjustment to the inputClasses computed property, utilizing the modified defaultInputClasses, ensures that the input's appearance remains customizable based on size and validation status.

@Sqrcz Sqrcz added the 🔧 enhancement New feature or request label Sep 6, 2024
@Sqrcz Sqrcz self-assigned this Sep 6, 2024
@Sqrcz
Copy link
Collaborator

Sqrcz commented Jan 8, 2025

Hey, @andreyjamer

Very good improvement 👍

In terms of sizes... wouldn't it be enough to use button sizes appropriate to input size that is being used? 🤔

Like this:
image

<fwb-input
  dir="rtl"
  label="Search"
  placeholder="enter your search query"
  size="sm"
>
  <template #prefix>
    <svg aria-hidden="true" class="w-5 h-5 text-gray-500 dark:text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
      <path d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" />
    </svg>
  </template>
  <template #suffix>
    <fwb-button size="xs">Search</fwb-button>
  </template>
</fwb-input>

I can merge it as it is right now... as it works properly... not sure if extra work for better size management is needed... let me know your thoughts on this.

@andreyjamer
Copy link
Contributor Author

The different buttons sizes work already as you described. I did some minor fixes related to the prefix/suffix margins and focus management. Now it should look and work like the current implementation.

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

🧹 Nitpick comments (3)
src/components/FwbInput/composables/useInputClasses.ts (1)

26-27: Consider extracting color values for better customization.

The validation states are well-implemented with proper dark mode support. However, consider extracting the color values into CSS variables or theme constants for easier customization.

docs/components/input/examples/FwbInputExampleSuffix.vue (2)

3-97: Good demonstration of size variants!

The examples effectively show how different input sizes work with corresponding button sizes, which helps validate the flex layout improvements.

Consider reducing SVG duplication

The search icon SVG is duplicated across all three examples. Consider extracting it into a reusable component.

+ // Create new file: src/components/icons/SearchIcon.vue
+ <template>
+   <svg
+     aria-hidden="true"
+     class="w-5 h-5 text-gray-500 dark:text-gray-400"
+     fill="none"
+     stroke="currentColor"
+     viewBox="0 0 24 24"
+     xmlns="http://www.w3.org/2000/svg"
+   >
+     <path
+       d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"
+       stroke-linecap="round"
+       stroke-linejoin="round"
+       stroke-width="2"
+     />
+   </svg>
+ </template>

// In FwbInputExampleSuffix.vue
+ import SearchIcon from '../../../src/components/icons/SearchIcon.vue'

- <svg>...</svg>
+ <SearchIcon />

5-5: Consider using separate v-model bindings for each input

Currently, all inputs share the same v-model="name", which means they'll all update simultaneously. For clearer examples, consider using distinct bindings:

- const name = ref('')
+ const searchLg = ref('')
+ const searchMd = ref('')
+ const searchSm = ref('')

- v-model="name"
+ v-model="searchLg"  // for size="lg" input
+ v-model="searchMd"  // for size="md" input
+ v-model="searchSm"  // for size="sm" input

Also applies to: 37-37, 69-69

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 62fb704 and 84fc746.

📒 Files selected for processing (3)
  • docs/components/input/examples/FwbInputExampleSuffix.vue (1 hunks)
  • src/components/FwbInput/FwbInput.vue (3 hunks)
  • src/components/FwbInput/composables/useInputClasses.ts (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build-pkg (20.x)
🔇 Additional comments (9)
src/components/FwbInput/composables/useInputClasses.ts (6)

13-14: Well-structured base input classes for RTL support!

The use of flex-grow and removal of default styles provides a clean foundation for RTL-friendly layouts.


36-39: Clean type definitions!

The TypeScript types are well-maintained and properly reflect the component's structure.


Line range hint 40-54: Well-structured computed property implementation!

The inputBlockClasses implementation properly handles validation states and disabled conditions while preventing class conflicts through twMerge.


56-58: Clean and concise implementation!

The simplified inputClasses computation maintains functionality while reducing complexity.


72-75: Clean return statement structure!

The return statement properly exposes all necessary classes while maintaining a logical order.


15-18: Verify browser compatibility for the has selector.

While using has-[input:focus] is an elegant solution for managing focus states, it's a relatively new CSS feature. Ensure it meets your browser support requirements.

Run this script to check browser compatibility data:

✅ Verification successful

:has selector has strong browser support

The has-[input:focus] selector is well-supported across all modern browsers:

  • Chrome/Edge: v105+ (Sept 2022)
  • Firefox: v121+ (Dec 2023)
  • Safari: v15.4+ (March 2022)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check browser compatibility for :has selector
curl -s 'https://raw.githubusercontent.com/mdn/browser-compat-data/main/css/selectors/has.json' | jq '.css.selectors.has.__compat.support'

Length of output: 597

src/components/FwbInput/FwbInput.vue (3)

7-10: Well-implemented RTL support using flex layout!

The switch from absolute positioning to flex layout with directional margin utilities (ms-2, me-2) provides proper RTL support. The flex-shrink-0 on prefix/suffix prevents unwanted collapsing.

Also applies to: 13-13, 24-24, 28-28


85-85: Good separation of concerns!

The addition of inputBlockClasses from the composable maintains clean separation of styling logic.


Line range hint 7-32: Verify accessibility in RTL mode

While the layout improvements for RTL are good, please ensure:

  1. Screen readers announce content in the correct order
  2. Focus indicators remain visible in RTL mode
  3. Input-prefix-suffix spacing remains adequate in RTL mode
✅ Verification successful

RTL and accessibility implementation verified as correct

The component correctly implements RTL support and accessibility:

  • Uses logical CSS properties (ms-/me-) for RTL-aware spacing
  • Maintains proper focus management across all states
  • Preserves correct reading order for screen readers through semantic markup
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for RTL-specific aria attributes or dir attributes
rg -l 'dir="rtl"|aria-' src/components/FwbInput/

# Check for any existing RTL tests
rg -l 'rtl|direction' src/components/FwbInput/__tests__/

Length of output: 184


Script:

#!/bin/bash
# Find test files for this component
fd -g "*FwbInput*.test.*" -g "*FwbInput*.spec.*"

# Search for RTL/direction related CSS classes and properties
rg -l "(ms-|me-|start-|end-|rtl|direction|ltr)" src/components/FwbInput/

# Check for focus and aria related styles/attributes
rg "(focus|:focus|aria-|role=)" src/components/FwbInput/

# Find component documentation or stories
fd -g "*FwbInput*.stories.*" -g "*FwbInput*.md"

Length of output: 1689

Copy link
Collaborator

@Sqrcz Sqrcz left a comment

Choose a reason for hiding this comment

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

Nice! It looks better now. Thank you!

@Sqrcz Sqrcz merged commit 6d39697 into themesberg:main Jan 9, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔧 enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants