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

Allow deselect when renderSelectedChoices enabled #1221

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

godismyjudge95
Copy link

Description

Drafting this PR as I am not sure if you would want to follow a different approach. If this looks good I can try to add tests.

There have been a few requests to allow for deselecting items via the dropdown when the renderSelectedChoices option is enabled. #804 #884

I ran across this issue myself while needing to keep a multiselect box footprint minimal (it grows to be pretty large when selecting a few options).

This PR has 3 parts:m

  • highlight selected choices in the dropdown when renderSelectedChoices is enabled
  • allow clicking on a selected choice in the dropdown to deselect the choice
  • add a new renderItems boolean option to disable the "pills" in the multiselect input to allow one to only select/deselect via the dropdown

Screenshots (if appropriate)

Example of having both renderSelectedChoices: 'always' and renderItems: false

image

Types of changes

  • Chore (tooling change or documentation change)
  • Refactor (non-breaking change which maintains existing functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • My code follows the code style of this project.
  • I have added new tests for the bug I fixed/the new feature I added.
  • I have modified existing tests for the bug I fixed/the new feature I added.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

@Xon Xon self-requested a review October 25, 2024 03:08
@@ -54,7 +54,7 @@ export interface Templates {

choiceGroup(options: TemplateOptions, group: GroupFull): HTMLDivElement;

choice(options: TemplateOptions, choice: ChoiceFull, selectText: string, groupText?: string): HTMLDivElement;
choice(options: TemplateOptions, choice: ChoiceFull, selectText: string, deselectText: string, groupText?: string): HTMLDivElement;
Copy link
Collaborator

@Xon Xon Oct 25, 2024

Choose a reason for hiding this comment

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

Instead of an argument, please use renderItems from the config. This can be done by adding it as a picked field for the TemplateOptions type.

This avoids a breaking change to the function signature.

text-align: right;
}
}
&[data-type*='select-multiple'] .#{$choices-selector}__item--selectable {
&.is-selected::after {
content: attr(data-deselect-text);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This CSS should be scoped to having [data-deselect-text] similar to how [data-select-text] has been done.

@@ -5,5 +5,5 @@ import { ChoiceFull } from '../interfaces/choice-full';
type MappedInputTypeToChoiceType<T extends string | InputChoice | InputGroup> = T extends InputGroup ? GroupFull : ChoiceFull;
export declare const coerceBool: (arg: unknown, defaultValue?: boolean) => boolean;
export declare const stringToHtmlClass: (input: string | string[] | undefined) => string[] | undefined;
export declare const mapInputToChoice: <T extends string | InputChoice | InputGroup>(value: T, allowGroup: boolean) => MappedInputTypeToChoiceType<T>;
export declare const mapInputToChoice: <T extends string | InputChoice | InputGroup>(value: T, allowGroup: boolean, allowRawString?: boolean) => MappedInputTypeToChoiceType<T>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This function's signature has changed and the compiled chocies.js has this function change, but the changes aren't committed to the .ts files.

Copy link
Collaborator

@Xon Xon left a comment

Choose a reason for hiding this comment

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

Please ensure unit tests and e2e tests are passing.

  • An e2e test for each functionality change should also be added. Ideally one each for text, select-one and select-multiple even if it is testing it doesn't do anything.

This change has a lot of unrelated code churn which complicates git blame. Please rebuild the PR without those changes to preserve git blame

Changes to .js files not matched in the .ts files. The .ts are the canonical source and the .js changes will be discard at the next build. There are significant changes not committed into the .ts

@Xon Xon added feature Pull request that adds new functionality changes required Pull request requires changes before it can be merged labels Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changes required Pull request requires changes before it can be merged feature Pull request that adds new functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants