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

[bug]: Multiple Selector clear all button #111

Closed
2 tasks done
Crea7orX opened this issue Jul 4, 2024 · 1 comment
Closed
2 tasks done

[bug]: Multiple Selector clear all button #111

Crea7orX opened this issue Jul 4, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Crea7orX
Copy link

Crea7orX commented Jul 4, 2024

Describe the bug

Multiple Selector clear all button when pressed not calling onChange event

Here is fixed code and better positioning of the button:
<div className="relative flex flex-wrap gap-1 pr-8"> {selected.map((option) => { return ( <Badge key={option.value} className={cn( "data-[disabled]:bg-muted-foreground data-[disabled]:text-muted data-[disabled]:hover:bg-muted-foreground", "data-[fixed]:bg-muted-foreground data-[fixed]:text-muted data-[fixed]:hover:bg-muted-foreground", badgeClassName )} data-fixed={option.fixed} data-disabled={disabled || undefined} > {option.label} <button className={cn( "ml-1 rounded-full outline-none ring-offset-background focus:ring-2 focus:ring-ring focus:ring-offset-2", (disabled || option.fixed) && "hidden" )} onKeyDown={(e) => { if (e.key === "Enter") { handleUnselect(option); } }} onMouseDown={(e) => { e.preventDefault(); e.stopPropagation(); }} onClick={() => handleUnselect(option)} > < className="h-3 w-3 text-muted-foreground hover:text-foreground" /> </button> </Badge> ); })} {/* Avoid having the "Search" Icon */} <CommandPrimitive.Input {...inputProps} ref={inputRef} value={inputValue} disabled={disabled} onValueChange={(value) => { setInputValue(value); inputProps?.onValueChange?.(value); }} onBlur={(event) => { if (!mouseOn.current) { setOpen(false); } inputProps?.onBlur?.(event); }} onFocus={(event) => { setOpen(true); triggerSearchOnFocus && onSearch?.(debouncedSearchTerm); inputProps?.onFocus?.(event); }} placeholder={ hidePlaceholderWhenSelected && selected.length !== 0 ? "" : placeholder } className={cn( "flex-1 bg-transparent outline-none placeholder:text-muted-foreground", { "w-full": hidePlaceholderWhenSelected, "px-3 py-2": selected.length === 0, "ml-1": selected.length !== 0, }, inputProps?.className )} /> {!( hideClearAllButton || disabled || selected.length < 1 || selected.filter((s) => s.fixed).length === selected.length ) && ( <Button variant="ghost" onClick={() => { setSelected( selected.filter((s) => s.fixed) ); onChange?.(selected.filter((s) => s.fixed)); }} className="absolute right-0 h-6 w-6 p-0" > <X /> </Button> )} </div>

Affected component/components

Multiple Selector

How to reproduce

  1. Import Multiple Selector component
  2. Use it in form
  3. Press clear all button
  4. Send the form
  5. See the problem

Codesandbox/StackBlitz link

No response

Logs

No response

System Info

No response

Before submitting

  • I've made research efforts and searched the documentation
  • I've searched for existing issues
@Crea7orX Crea7orX added the bug Something isn't working label Jul 4, 2024
ezeparziale added a commit to ezeparziale/shadcn-ui-expansions that referenced this issue Jul 6, 2024
@ezeparziale
Copy link
Contributor

I created a PR #112

hsuanyi-chou pushed a commit that referenced this issue Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants