Skip to content

Commit

Permalink
Merge pull request #4666 from julien/issue/4663
Browse files Browse the repository at this point in the history
fix(@clayui/core): avoid scrolling when selecting a node
  • Loading branch information
matuzalemsteles authored Feb 14, 2022
2 parents 2cafb16 + 33f0f1e commit 6ae276a
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/clay-core/src/tree-view/TreeViewItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ export const TreeViewItem = React.forwardRef<
}}
onFocus={() => actions && setFocus(true)}
onKeyDown={(event) => {
event.preventDefault();

const {key} = event;

if (key === Keys.Left) {
Expand Down
65 changes: 65 additions & 0 deletions packages/clay-core/stories/TreeView.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1192,4 +1192,69 @@ storiesOf('Components|ClayTreeView', module)
</TreeView>
</Provider>
);
})
.add('no scrolling', () => {
// Just to avoid TypeScript error with required props
const OptionalCheckbox = (props: any) => <Checkbox {...props} />;

OptionalCheckbox.displayName = 'ClayCheckbox';

const [items, _setItems] = React.useState([
{
children: [{name: 'Blogs'}, {name: 'Documents and Media'}],
name: 'Liferay Drive',
},
{
children: [{name: 'Blogs'}, {name: 'Documents and Media'}],
name: 'Repositories',
},
{
children: [
{name: 'PDF'},
{name: 'Word'},
{name: 'Google Drive'},
{name: 'Figma'},
],
name: 'Documents and Media',
},
{
children: [{name: 'One'}, {name: 'Two'}, {name: 'Three'}],
name: 'Another directory',
},
{
children: [{name: 'Four'}, {name: 'Five'}, {name: 'Six'}],
name: 'Last directory',
},
]);

return (
<Provider spritemap={spritemap} theme="cadmin">
<div
style={{
background: 'hotpink',
height: '150px',
overflow: 'auto',
}}
>
<TreeView dragAndDrop items={items} nestedKey="children">
{(item) => (
<TreeView.Item>
<TreeView.ItemStack>
<OptionalCheckbox />
{item.name}
</TreeView.ItemStack>
<TreeView.Group items={item.children}>
{(item) => (
<TreeView.Item>
<OptionalCheckbox />
{item.name}
</TreeView.Item>
)}
</TreeView.Group>
</TreeView.Item>
)}
</TreeView>
</div>
</Provider>
);
});

0 comments on commit 6ae276a

Please sign in to comment.