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

Rewrite select #137

Merged
merged 32 commits into from
Sep 26, 2023
Merged

Rewrite select #137

merged 32 commits into from
Sep 26, 2023

Conversation

vineethasok
Copy link
Collaborator

@vineethasok vineethasok commented Sep 12, 2023

Screen.Recording.2023-09-21.at.08.56.51.mov
Screenshot 2023-09-25 at 22 45 07

@vineethasok vineethasok self-assigned this Sep 12, 2023
@vercel
Copy link

vercel bot commented Sep 12, 2023

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

Name Status Preview Comments Updated (UTC)
click-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 26, 2023 1:48pm

@vineethasok
Copy link
Collaborator Author

@serdec @fneves I'm facing 2 issues in this PR

  • The trigger is loaded before the content and the element value is not added on initial render
  • On Multi Select when we are dragging outside the select trigger and dropping it won't revert the change entirely and move to the previous change. For example if there are 3 elements and the first element is dragged above the second one and then without dropping I drag it outside the trigger element then the second position is added and not reverted to the first position

@fneves
Copy link
Collaborator

fneves commented Sep 15, 2023

Have a look at this: https://ui.shadcn.com/docs/components/combobox
Its based in radix and I think its what we want.

@vineethasok
Copy link
Collaborator Author

@fneves The way they do it is using the cmdk package and we have encountered the problem of case sensitiveness when navigating through options
That's why we are trying to rewrite the select package

@serdec
Copy link
Collaborator

serdec commented Sep 15, 2023

@serdec @fneves I'm facing 2 issues in this PR

  • The trigger is loaded before the content and the element value is not added on initial render
  • On Multi Select when we are dragging outside the select trigger and dropping it won't revert the change entirely and move to the previous change. For example if there are 3 elements and the first element is dragged above the second one and then without dropping I drag it outside the trigger element then the second position is added and not reverted to the first position

@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

@serdec
Copy link
Collaborator

serdec commented Sep 16, 2023

the documentation is not showing up correctly

image

@serdec
Copy link
Collaborator

serdec commented Sep 16, 2023

it seems the showSearch flag doesn't work correctly

image

}: MultiSelectProps) => {
const defaultId = useId();
const inputRef = useRef<HTMLInputElement>(null);
const [open, setOpen] = useState(defaultOpen ?? openProp);
Copy link
Collaborator

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.

Copy link
Collaborator Author

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

@vineethasok
Copy link
Collaborator Author

@serdec The sort issue is fixed only issue is the first time visibility of the elements
I managed to fix the item loading on initial render issue too
But not confident it is the right way

const Trigger = forwardRef<HTMLButtonElement, TriggerProps>(
({ placeholder = "Select an option", onClick: onClickProp, ...props }, ref) => {
const [, forceUpate] = useState(0);
const { disabled, id, hasError, selectedValues, updateSearch, getValueProps } =
Copy link
Collaborator Author

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 elements such as disabled, id, hasError should be moved to a different context and also I should create a separate component with the useCombobox for the value only?


export const ComboboxGroup = forwardRef<HTMLDivElement, GroupProps>(
({ children, heading, ...props }, forwardedRef) => {
useCombobox(); // inorder to refresh the content on search
Copy link
Collaborator Author

@vineethasok vineethasok Sep 16, 2023

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;

defaultOpen?: boolean;
}

export const MultiSelect = ({
Copy link
Collaborator

Choose a reason for hiding this comment

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

options are not aligned if there's an icon

image

);
const [open, setOpen] = useState(false);

const onOpenChange = useCallback((newOpen?: boolean) => {
Copy link
Collaborator

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>
Copy link
Collaborator

Choose a reason for hiding this comment

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

label is not aligned when there's an error

image

Copy link
Collaborator Author

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

Copy link
Collaborator

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}
Copy link
Collaborator

Choose a reason for hiding this comment

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

the options property is not displayed

image

Comment on lines 40 to 48
const onChange = useCallback(
(values: Array<string>) => {
setSelectedValues(values);
if (typeof onChangeProp === "function") {
onChangeProp(values);
}
},
[onChangeProp]
);
Copy link
Collaborator

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?

Copy link
Collaborator Author

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

Copy link
Collaborator

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

Copy link
Collaborator Author

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) => {
Copy link
Collaborator

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

Copy link
Collaborator Author

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
Copy link
Collaborator

gjones commented Sep 25, 2023

Select component

  • When disabled, can we add cursor: not-allowed
  • When show search is enabled, there's an extra horizontal line that I don't think we need.
CleanShot 2023-09-25 at 15 07 06@2x

Multiselect component

  • I see it (looks great) but I can't interact with it. x doesn't do anything and I can't select new options.

@vineethasok
Copy link
Collaborator Author

Select component

  • When disabled, can we add cursor: not-allowed
  • When show search is enabled, there's an extra horizontal line that I don't think we need.
CleanShot 2023-09-25 at 15 07 06@2x ### Multiselect component * I see it (looks great) but I can't interact with it. `x` doesn't do anything and I can't select new options.

@gjones
The close is working but when a value is provided then that value is respected over the one which we use inside
Remove the value in stories and try selecting and deleting it
It Will work

Regarding the line
I copied the design from this figma file and it has a line under the select
Should I remove it?
https://www.figma.com/file/mjSci5n5YREyVlvaVjMSDq/Click-UI-Library?type=design&node-id=472%3A6842&mode=design&t=zME5E6bf4uUv5Xbr-1

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.

4 participants