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

fix(CheckTreePicker): fix root node style incorrect #2279

Merged
merged 1 commit into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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