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

selectedIds sometimes not rendering correctly #212

Open
mrevanzak opened this issue Feb 19, 2025 · 0 comments
Open

selectedIds sometimes not rendering correctly #212

mrevanzak opened this issue Feb 19, 2025 · 0 comments

Comments

@mrevanzak
Copy link

mrevanzak commented Feb 19, 2025

Describe the bug
If i provide the selectedIds on all of the children, the parrent sometimes wont be selected

Code That Causes The Issue

export default function TreeSelect(
  props: Omit<Partial<ITreeViewProps>, "data"> & {
    data?: TreeSelectData;
  },
) {
  const flattenData = useMemo((): INode<IFlatMetadata>[] => {
    if (!props.data) {
      return [
        {
          id: "0",
          name: "No data",
          children: [],
          parent: null,
        },
      ];
    }
    return flattenTree(props.data);
  }, [props.data]);

  return (
    <TreeView
      {...props}
      data={flattenData}
      aria-label="Checkbox tree"
      multiSelect
      propagateSelect
      propagateSelectUpwards
      togglableSelect
      nodeRenderer={({
        element,
        isBranch,
        isExpanded,
        isSelected,
        isHalfSelected,
        getNodeProps,
        level,
        handleSelect,
        handleExpand,
      }) => (
        <div
          {...getNodeProps({ onClick: handleExpand })}
          className={cn(
            "flex justify-between items-center transition-all duration-200 py-6",
            getNodeProps().className,
            {
              "py-3 ml-2": level > 1,
              "border-b border-secondary-80": isExpanded && level === 1,
              "border-l pl-3 border-secondary-90": level > 2,
            },
          )}
        >
          <div className="flex flex-row items-center space-x-2">
            <CheckBoxIcon
              onClick={(e) => {
                e.stopPropagation();
                handleSelect(e);
              }}
              variant={isHalfSelected ? "some" : isSelected ? "all" : "none"}
              className={cn({
                "bg-brand-30": isSelected,
              })}
            />
            <p className="text-base">{element.name}</p>
          </div>
          {isBranch && (
            <ChevronDown
              className={cn(
                "size-4 shrink-0 text-brand-30 transition-transform duration-200",
                {
                  "rotate-180": isExpanded,
                },
              )}
            />
          )}
        </div>
      )}
    />
  );
}

To Reproduce
Steps to reproduce the behavior:
Navigate to the page that contains this component. Go back and visit the page repeatedly to check if it renders correctly. Sometimes it does, and sometimes it doesn’t.

Expected behavior
Should always be selected correctly

Screenshots

Image Image

Desktop (please complete the following information):

  • OS: MacOS Sequoia
  • Browser: all chromium base

Additional context
if i do a hard refresh on the page that has this component, it 100% will be rendered correctly

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

No branches or pull requests

1 participant