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

fix: support "disabled" state in MultiSelect #1377

Closed
wants to merge 1 commit into from

Conversation

MeoMix
Copy link

@MeoMix MeoMix commented Jun 27, 2024

Closes #1349

📑 Description

Currently, MultiSelect remains receptive to user input even if disabled=true is passed

This PR minimally addresses that issue by introducing disabled state and adjusting the UI to accommodate. The cursor changes to "not-allowed", elements gray out, and user input is denied.

I tried to change as little as possible and just get in/out with a laser fix. I'm not especially interested in putting a lot of time into this project (sorry!) just trying to be kind and upstream a patch for a bug I encountered.

Status

  • Not Completed
  • Completed

✅ Checks

If someone would like to go through these checks - by all means. I tested locally on my own project by copy/pasting the existing component into my codebase and it works on my machine.

  • My pull request adheres to the code style of this project
  • My code requires changes to the documentation
  • I have updated the documentation as required
  • I have checked the page with https://validator.unl.edu/
  • All the tests have passed
  • My pull request is based on the latest commit (not the npm version).

ℹ Additional Information

image

Summary by CodeRabbit

  • New Features
    • Added a disabled property to the MultiSelect component, allowing users to control the component's interactivity. When set to true, the component will be non-interactive.

Prevent user interaction when MultiSelect is disabled and update UI to hint at disabled state
Copy link

vercel bot commented Jun 27, 2024

@MeoMix is attempting to deploy a commit to the Themesberg Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Jun 27, 2024

Walkthrough

The MultiSelect component in src/lib/forms/MultiSelect.svelte has been enhanced with a disabled property to control its interactivity. This change ensures that when disabled is true, users cannot interact with the component, addressing previous issues where the disabled state was ineffective.

Changes

Files Change Summary
src/lib/forms/MultiSelect.svelte Added a disabled property and updated functions to check this property before executing actions.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant MultiSelect

    User->>MultiSelect: Attempt interaction (click/add/remove)
    alt MultiSelect is disabled
        MultiSelect-->>User: No action taken
    else MultiSelect is enabled
        MultiSelect-->>User: Interaction proceeds as normal
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Ensure MultiSelect disabled state is effective (#1349)

Poem

In the garden of code, where devs like to roam,
A MultiSelect blooms, no longer alone.
With disabled in place, it stands with grace,
Shielding itself in a tranquil embrace.
Input ignored, when disabled implores,
A guardian of states, that users adore. 🌼


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 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @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.
  • 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.

@@ -21,7 +22,7 @@
};

// Container
const multiSelectClass: string = 'relative border border-gray-300 flex items-center rounded-lg gap-2 dark:border-gray-600 focus-within:ring-1 focus-within:border-primary-500 ring-primary-500 dark:focus-within:border-primary-500 dark:ring-primary-500 focus-visible:outline-none';
const multiSelectClass: string = 'relative border border-gray-300 flex items-center rounded-lg gap-2 dark:border-gray-600 ring-primary-500 dark:ring-primary-500 focus-visible:outline-none';
Copy link
Author

Choose a reason for hiding this comment

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

Here I ensure that clicking the input doesn't highlight it when focused. Visually this is good, but conceptually I don't think any of the children should be retaining focus. I think it would be better to try and propagate the disabled state through all the children for accessibility, but I didn't attempt to do that.

{#if !selectItems.length}
<span class="text-gray-400">{placeholder}</span>
{/if}
<span class="flex gap-2 flex-wrap">
{#if selectItems.length}
{#each selectItems as item (item.name)}
<slot {item} clear={() => clearThisOption(item)}>
<Badge color="dark" large={size === 'lg'} dismissable params={{ duration: 100 }} on:close={() => clearThisOption(item)}>
<Badge color="dark" large={size === 'lg'} dismissable params={{ duration: 100 }} on:close={() => clearThisOption(item)} class={disabled && "pointer-events-none"} >
Copy link
Author

Choose a reason for hiding this comment

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

It's probably overkill to do pointer-events: none here since all helper methods have early exits, but meh.

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 ddb09b3 and 0d882e9.

Files selected for processing (1)
  • src/lib/forms/MultiSelect.svelte (10 hunks)
Additional comments not posted (7)
src/lib/forms/MultiSelect.svelte (7)

14-14: New disabled property added.

The addition of a disabled property is essential for implementing the disabled state functionality. This change is well-implemented and follows Svelte's reactive declaration pattern.


42-44: Ensure all interaction handlers respect the disabled state.

All key interaction handlers (selecting options, clearing options, keyboard navigation) correctly check the disabled property before proceeding. This ensures that no actions are performed when the component is disabled.

Also applies to: 55-57, 65-67, 77-79, 86-88, 99-101, 117-119


151-151: UI state handling for disabled MultiSelect.

The div handling clicks and focus-out events correctly checks the disabled state before toggling visibility. This prevents any interaction when the component is disabled, which is crucial for accessibility and user experience.


159-159: Badge component handling in disabled state.

The Badge component within the slot correctly adds a pointer-events-none class when the component is disabled. This is a good use of conditional rendering to ensure that UI elements inside the MultiSelect do not respond to user interactions when disabled.
[APROVED]


168-168: Close button disabled state handling.

The CloseButton component is appropriately disabled when the MultiSelect is disabled. This is done through both a disabled attribute and conditional class application, which is a robust approach to ensure the button is non-interactive.


171-171: Dropdown arrow handling in disabled state.

The SVG for the dropdown arrow correctly applies the cursor-not-allowed style when the component is disabled. This visual cue is important for indicating to the user that the component is non-interactive.


180-180: Conditional rendering for item selection in disabled state.

The div that allows item selection within the dropdown applies pointer-events-none when the component is disabled. This prevents any selection actions, aligning with the intended functionality of the disabled state.

Copy link

vercel bot commented Jun 30, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
flowbite-svelte ❌ Failed (Inspect) Jun 30, 2024 1:30pm

@shinokada
Copy link
Collaborator

Thank you for your contribution. Your function is applied but not from this PR.

https://flowbite-svelte.com/docs/forms/select#Disabled_option

@shinokada shinokada closed this Oct 16, 2024
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.

MultiSelect disabled state is ineffective
2 participants