Skip to content

Commit

Permalink
fix(CheckTreePicker): fix root node style incorrect (#2279)
Browse files Browse the repository at this point in the history
  • Loading branch information
superman66 committed Jan 6, 2022
1 parent bd0f5e3 commit c09226e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/CheckTreePicker/CheckTreePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ const CheckTreePicker: PickerComponent<CheckTreePickerProps> = React.forwardRef(
const renderCheckTree = () => {
const classes = withCheckTreeClassPrefix({
[className ?? '']: inline,
'without-children': !isSomeNodeHasChildren,
'without-children': !isSomeNodeHasChildren(data, childrenKey),
virtualized
});

Expand Down
2 changes: 1 addition & 1 deletion src/CheckTreePicker/styles/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
}

// Only has the first level
.without-children & {
.rs-check-tree-without-children & {
padding-left: 34px; //text gap + checkbox space

&::before {
Expand Down
7 changes: 7 additions & 0 deletions src/CheckTreePicker/test/CheckTreePickerStylesSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,11 @@ describe('CheckTreePicker styles', () => {
const itemLabel = document.body.querySelector('.rs-check-tree .rs-checkbox-checker label');
assert.equal(getStyle(itemLabel, 'padding'), '8px 12px 8px 58px');
});

itChrome('Should render the correct styles when data has only one level structure', () => {
const instanceRef = React.createRef();
render(<CheckTreePicker data={[{ value: 1, label: 1 }]} ref={instanceRef} open />);
const itemLabel = document.body.querySelector('.rs-check-tree .rs-checkbox-checker label');
assert.equal(getStyle(itemLabel, 'padding'), '8px 12px 8px 34px');
});
});
2 changes: 1 addition & 1 deletion src/CheckTreePicker/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function isSomeChildChecked(
}

export function isSomeNodeHasChildren(data: any[], childrenKey: string): boolean {
return data.some((node: TreeNodeType) => node[childrenKey]);
return data.some((node: TreeNodeType) => Array.isArray(node[childrenKey]));
}

/**
Expand Down

1 comment on commit c09226e

@vercel
Copy link

@vercel vercel bot commented on c09226e Jan 6, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.