-
Notifications
You must be signed in to change notification settings - Fork 8
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
Rewrite select #137
Rewrite select #137
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@serdec @fneves I'm facing 2 issues in this PR
|
Have a look at this: https://ui.shadcn.com/docs/components/combobox |
@fneves The way they do it is using the cmdk package and we have encountered the problem of case sensitiveness when navigating through options |
@vineethasok where do we use the select with drag and drop at the moment? Maybe if it is giving us too many troubles we can ditch the drag an drop for now and implement a simpler version and refine it later on |
}: MultiSelectProps) => { | ||
const defaultId = useId(); | ||
const inputRef = useRef<HTMLInputElement>(null); | ||
const [open, setOpen] = useState(defaultOpen ?? openProp); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would avoid setting the internal open state as this can lead to inconsistencies such as a situation where the user open
state is false
but the select is open.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is added as in radix ui in order to have an option to not declare it externally and we can still have the functionality
In this case the user can define the initial open state and not manage the open state externally and use the select like normally
@serdec The sort issue is fixed only issue is the first time visibility of the elements |
src/components/Select/Select.tsx
Outdated
const Trigger = forwardRef<HTMLButtonElement, TriggerProps>( | ||
({ placeholder = "Select an option", onClick: onClickProp, ...props }, ref) => { | ||
const [, forceUpate] = useState(0); | ||
const { disabled, id, hasError, selectedValues, updateSearch, getValueProps } = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
export const ComboboxGroup = forwardRef<HTMLDivElement, GroupProps>( | ||
({ children, heading, ...props }, forwardedRef) => { | ||
useCombobox(); // inorder to refresh the content on search |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@serdec @fneves @gjones Do you think I should create a hook as below inorder for this component to be rerendered only on search?
import { useMemo } from "react";
import { useCombobox } from "./useCombobox";
const useSearch = () => {
const { search } = useCombobox();
const searchValue = useMemo(() => search, [search]);
return searchValue;
};
export default useSearch;
09a7a61
to
c1ecdba
Compare
103e821
to
3037322
Compare
defaultOpen?: boolean; | ||
} | ||
|
||
export const MultiSelect = ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
); | ||
const [open, setOpen] = useState(false); | ||
|
||
const onOpenChange = useCallback((newOpen?: boolean) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't need to pass newOpen
height?: number | string; | ||
}) => { | ||
return ( | ||
<LabelContainer> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error may happen to the input and other form elements too
Should I fix them in this PR or a new one separately for them? @serdec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another one is ok
onCreateOption={ | ||
clickableNoData ? search => console.log("Clicked ", search) : undefined | ||
} | ||
options={selectOptions} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const onChange = useCallback( | ||
(values: Array<string>) => { | ||
setSelectedValues(values); | ||
if (typeof onChangeProp === "function") { | ||
onChangeProp(values); | ||
} | ||
}, | ||
[onChangeProp] | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we really need this onChange
prop? how should the user use it compared to the onSelect
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Change Passes the entire list
In case on onSelectpeople expect the last clicked element in case of addition of removal
I can add the onSelect if needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think the onSelect should pass all the selected values so that the user doesn't have to keep track of the changes and we can get rid of the onChanges
prop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it will rename onChange with onSelect
@@ -26,8 +26,8 @@ export const Select = ({ | |||
); | |||
const [open, setOpen] = useState(false); | |||
|
|||
const onOpenChange = useCallback((newOpen?: boolean) => { | |||
setOpen(open => newOpen ?? !open); | |||
const onOpenChange = useCallback((open: boolean) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be a toggle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use onOpenChange for the radix-based items like dropdown, context menu , tooltip and all
So in order to have consistency I added onOpenChange instead of onToggle
@gjones Regarding the line |
Screen.Recording.2023-09-21.at.08.56.51.mov