Closed Crea7orX closed 4 months ago
Multiple Selector clear all button when pressed not calling onChange event
Here is fixed code and better positioning of the button: `
{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" /> ); })} {/ 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" )}
{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" /> ); })} {/ 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"
)}
Multiple Selector
No response
I created a PR https://github.com/hsuanyi-chou/shadcn-ui-expansions/pull/112
Describe the bug
Multiple Selector clear all button when pressed not calling onChange event
Here is fixed code and better positioning of the button: `
Affected component/components
Multiple Selector
How to reproduce
Codesandbox/StackBlitz link
No response
Logs
No response
System Info
No response
Before submitting