Skip to content

autoDismiss prop in auto complete input type - #70

Open
shahzaib3120 wants to merge 1 commit into
fateh999:masterfrom
shahzaib3120:feature/autoDismiss_AutoComplete
Open

shahzaib3120 wants to merge 1 commit into
fateh999:masterfrom
shahzaib3120:feature/autoDismiss_AutoComplete

Conversation

@shahzaib3120

@shahzaib3120 shahzaib3120 commented Jan 28, 2024

Copy link
Copy Markdown

The user might want to close the modal after selecting a value in the AutoComplete input type to avoid having to click the action button in the top right corner.

I added an optional autoDismiss prop which if set to true automatically closes the modal. and omitting it or setting it to false shows the default behavior.

Summary by CodeRabbit

  • New Features
    • Introduced an autoDismiss feature for autocomplete components, allowing for automatic dismissal of suggestions upon selection.
  • Refactor
    • Updated AutoComplete and InputAutocomplete components to support the new autoDismiss property.
  • Documentation
    • Added documentation for the autoDismiss property in autocomplete components.

@coderabbitai

coderabbitai Bot commented Jan 28, 2024

Copy link
Copy Markdown

Walkthrough

The recent updates focus on enhancing user interaction with autocomplete components. A notable addition is the autoDismiss property, aimed at providing control over the automatic dismissal of the autocomplete modal or suggestions upon selection. This feature, alongside minor UI adjustments like updated testID attributes and modified placeholder texts, enriches the user experience by offering more intuitive and customizable interactions.

Changes

File Path Change Summary
.../AutoComplete.tsx Introduced autoDismiss prop; minor updates to testID attributes and search bar placeholder.
.../InputAutocomplete.tsx Added autoDismiss prop with a default of false; conditional assignment of autoDismiss.
src/Types/Types.ts Added autoDismiss property to InputAutocompleteProps and AutoCompleteProps types.

🐰✨
In the code's vast meadow, under the bright moon's glow,
A tiny feature hops in, soft as the evening's snow.
"Dismiss me not," it whispers, to the user's delight,
For with a gentle touch, the UI takes its flight.
🌟🌙

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between d0487b3 and ab58577.
Files selected for processing (3)
  • src/Components/AutoComplete.tsx (4 hunks)
  • src/Inputs/InputAutocomplete.tsx (2 hunks)
  • src/Types/Types.ts (2 hunks)
Additional comments: 8
src/Inputs/InputAutocomplete.tsx (1)
  • 70-70: Passing the dismiss variable to the AutoComplete component as autoDismiss is correctly implemented. However, ensure that the AutoComplete component's prop types are updated to reflect this new property, and consider the previous suggestion to simplify the handling of autoDismiss.
src/Types/Types.ts (2)
  • 62-62: The addition of the autoDismiss property to InputAutocompleteProps with an optional boolean type is correctly implemented. This change accurately reflects the new functionality introduced in the InputAutocomplete component.
  • 71-71: The autoDismiss property in AutoCompleteProps is correctly added as a non-optional boolean. This enforces the requirement for this property when the AutoComplete component is used, aligning with the component's updated logic that relies on this property.
src/Components/AutoComplete.tsx (5)
  • 14-15: The destructuring of autoDismiss along with other props is correctly implemented. This setup allows the AutoComplete component to utilize the autoDismiss property effectively within its logic.
  • 36-40: The removal of spaces in the testID template literals is a minor change that improves consistency in the codebase. This change is correctly applied to the Appbar.Action component for the close icon.
  • 33-46: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [43-49]

Similarly, the adjustment to the testID for the check icon in the Appbar.Action component is correctly implemented, enhancing consistency in the use of testID attributes throughout the component.

  • 55-62: The update to the Searchbar component's testID and placeholder text follows the same pattern of improving consistency and clarity in the code. The conditional rendering of the placeholder text based on the presence of a placeholder prop or defaulting to a generic search label is a thoughtful touch.
  • 75-78: The implementation of the autoDismiss logic within the List.Item onPress event handler is correct. It ensures that if autoDismiss is true, selecting an item not only updates the field value but also dismisses the modal, aligning with the PR's objective to streamline user interactions.

options,
CustomAutoComplete,
CustomTextInput,
autoDismiss,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The autoDismiss property is destructured from props but lacks documentation. Consider adding a comment explaining its purpose and behavior, especially since it influences the modal's dismissal logic.

+  // autoDismiss controls if the modal should close automatically upon selection
   autoDismiss,

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.

Suggested change
autoDismiss,
// autoDismiss controls if the modal should close automatically upon selection
autoDismiss,

const errorMessage = formState.errors?.[field.name]?.message;
const textColor = errorMessage ? theme.colors.error : theme.colors.text;
const [visible, setVisible] = useState(false);
const dismiss = autoDismiss ?? false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The conditional assignment of autoDismiss to false if not provided is correct. However, this logic could be simplified by setting a default prop value for autoDismiss, which would make the component cleaner and more readable.

-  const dismiss = autoDismiss ?? false;
+  // Moved to default props for cleaner code

And then add to the bottom of the file:

+ InputAutocomplete.defaultProps = {
+   autoDismiss: false,
+ };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant