This repository has been archived by the owner on May 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix focus management issue when updating folder tree children (#2119)
- Loading branch information
Showing
11 changed files
with
214 additions
and
33 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file modified
BIN
-1.16 KB
(97%)
...ight-theme/en/chrome_medium/compact-interactive-list-spec/focused-hyperlink.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+184 Bytes
(100%)
...ault-theme/en/chrome_medium/compact-interactive-list-spec/focused-hyperlink.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+17.6 KB
...ence/clinical-lowlight-theme/en/chrome_medium/folder-tree-spec/reload-focus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+15 KB
...reference/orion-fusion-theme/en/chrome_medium/folder-tree-spec/reload-focus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+18 KB
...eference/terra-default-theme/en/chrome_medium/folder-tree-spec/reload-focus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
166 changes: 166 additions & 0 deletions
166
packages/terra-framework-docs/src/terra-dev-site/test/folder-tree/FolderTreeReload.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
import React, { useState } from 'react'; | ||
|
||
import { IconDocuments } from 'terra-icon'; | ||
import FolderTree from 'terra-folder-tree'; | ||
|
||
const data = { | ||
title: 'Documents', | ||
items: [ | ||
{ id: 'item-1-level-1', label: 'Information', icon: <IconDocuments /> }, | ||
{ | ||
id: 'item-2-level-1', label: 'Projects - 2023', icon: <IconDocuments />, isSelectable: false, | ||
}, | ||
{ | ||
id: 'item-3-level-1', | ||
label: 'Projects - 2023', | ||
isSelectable: false, | ||
items: [ | ||
{ id: 'item-1-level-2-1', label: 'Project Data - October', icon: <IconDocuments /> }, | ||
{ id: 'item-2-level-2-1', label: 'Project Data - November', icon: <IconDocuments /> }, | ||
{ id: 'item-3-level-2-1', label: 'Project Data - December', icon: <IconDocuments /> }, | ||
{ | ||
id: 'item-4-level-2-1', | ||
label: 'Tests', | ||
isSelectable: false, | ||
items: [ | ||
{ id: 'item-1-level-3-1', label: 'Very Very Very Very Very Very Very Long Name Test', icon: <IconDocuments /> }, | ||
{ id: 'item-2-level-3-1', label: 'Even Looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooonger Name Test', icon: <IconDocuments /> }, | ||
], | ||
}, | ||
], | ||
}, | ||
{ id: 'item-4-level-1', label: 'Projects - 2024', icon: <IconDocuments /> }, | ||
{ | ||
id: 'item-5-level-1', | ||
label: 'Projects - 2024', | ||
isSelectable: false, | ||
items: [ | ||
{ id: 'item-1-level-2-2', label: 'Project Data - January', icon: <IconDocuments /> }, | ||
], | ||
}, | ||
], | ||
reloadItems: [ | ||
{ id: 'reload-item-1-level-1', label: 'Information', icon: <IconDocuments /> }, | ||
{ | ||
id: 'reload-item-2-level-1', label: 'Projects - 2024', icon: <IconDocuments />, isSelectable: false, | ||
}, | ||
{ | ||
id: 'reload-item-3-level-1', | ||
label: 'Projects - 2024', | ||
isSelectable: false, | ||
items: [ | ||
{ id: 'reload-item-1-level-2-1', label: 'Project Data - January', icon: <IconDocuments /> }, | ||
{ id: 'reload-item-2-level-2-1', label: 'Project Data - February', icon: <IconDocuments /> }, | ||
{ id: 'reload-item-3-level-2-1', label: 'Project Data - March', icon: <IconDocuments /> }, | ||
{ | ||
id: 'reload-item-4-level-2-1', | ||
label: 'Tests', | ||
isSelectable: false, | ||
items: [ | ||
{ id: 'reload-item-1-level-3-1', label: 'Very Very Very Very Very Very Very Long Name Test', icon: <IconDocuments /> }, | ||
{ id: 'reload-item-2-level-3-1', label: 'Even Looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooonger Name Test', icon: <IconDocuments /> }, | ||
], | ||
}, | ||
], | ||
}, | ||
{ id: 'reload-item-4-level-1', label: 'Projects - 2025', icon: <IconDocuments /> }, | ||
{ | ||
id: 'reload-item-5-level-1', | ||
label: 'Projects - 2025', | ||
isSelectable: false, | ||
items: [ | ||
{ id: 'reload-item-1-level-2-2', label: 'Project Data - January', icon: <IconDocuments /> }, | ||
], | ||
}, | ||
], | ||
}; | ||
|
||
const folderExpandedState = { | ||
'item-3-level-1': false, | ||
'item-4-level-2-1': false, | ||
'item-5-level-1': false, | ||
}; | ||
|
||
const FolderTreeReload = () => { | ||
const [selectedKey, setSelectedKey] = useState(''); | ||
const [expandedItems, setExpandedItems] = useState(folderExpandedState); | ||
const [isReloaded, setReloaded] = useState(false); | ||
|
||
const handleExpandCollapseKeys = (key) => { | ||
const newExpandedItems = { | ||
...expandedItems, | ||
[key]: !expandedItems[key], | ||
}; | ||
setExpandedItems(newExpandedItems); | ||
}; | ||
|
||
const handleExpandAll = () => { | ||
const newExpandedItems = { | ||
...expandedItems, | ||
}; | ||
Object.keys(newExpandedItems).forEach(v => { newExpandedItems[v] = true; }); | ||
|
||
setExpandedItems(newExpandedItems); | ||
}; | ||
|
||
const handleCollapseAll = () => { | ||
const newExpandedItems = { | ||
...expandedItems, | ||
}; | ||
Object.keys(newExpandedItems).forEach(v => { newExpandedItems[v] = false; }); | ||
|
||
setExpandedItems(newExpandedItems); | ||
}; | ||
|
||
const buildFolderTreeItems = (items) => { | ||
if (items) { | ||
const elements = []; | ||
items.forEach(item => { | ||
elements.push( | ||
<FolderTree.Item | ||
key={item.id} | ||
label={item.label} | ||
icon={item.icon} | ||
subfolderItems={buildFolderTreeItems(item.items)} | ||
isExpanded={expandedItems[item.id]} | ||
isSelectable={item.isSelectable} | ||
isSelected={selectedKey === item.id} | ||
onSelect={() => { setSelectedKey(item.id); }} | ||
onToggle={() => { handleExpandCollapseKeys(item.id); }} | ||
/>, | ||
); | ||
}); | ||
return elements; | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
const reloadItems = () => { | ||
setReloaded(true); | ||
|
||
setExpandedItems({ | ||
'reload-item-3-level-1': false, | ||
'reload-item-4-level-2-1': false, | ||
'reload-item-5-level-1': false, | ||
}); | ||
}; | ||
|
||
return ( | ||
<> | ||
<button id="reload-data-button" type="button" onClick={reloadItems}> Reload Data</button> | ||
<br /> | ||
<div id="folder-tree-reload"> | ||
<FolderTree | ||
title={data.title} | ||
onExpandAll={handleExpandAll} | ||
onCollapseAll={handleCollapseAll} | ||
> | ||
{buildFolderTreeItems(isReloaded ? data.reloadItems : data.items)} | ||
</FolderTree> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default FolderTreeReload; |