diff --git a/packages/react-core/src/demos/examples/Tabs/TabsAndTable.tsx b/packages/react-core/src/demos/examples/Tabs/TabsAndTable.tsx index 956ac4c99f6..0392b32e1af 100644 --- a/packages/react-core/src/demos/examples/Tabs/TabsAndTable.tsx +++ b/packages/react-core/src/demos/examples/Tabs/TabsAndTable.tsx @@ -94,20 +94,12 @@ export const TablesAndTabs = () => { lastCommit: 'Last commit' }; - const [selectedRepoNames, setSelectedRepoNames] = React.useState([]); - const setRepoSelected = (event: React.FormEvent, repo: Repository, isSelecting = true) => { - setSelectedRepoNames((prevSelected) => { - const otherSelectedRepoNames = prevSelected.filter((r) => r !== repo.name); - return isSelecting ? [...otherSelectedRepoNames, repo.name] : otherSelectedRepoNames; - }); - event.stopPropagation(); + const [selectedRepoName, setSelectedRepoName] = React.useState(repositories[0].name); + const isRepoSelected = (repo: Repository) => repo.name === selectedRepoName; + const setRepoSelected = (_event: React.FormEvent, repo: Repository) => { + setSelectedRepoName(repo.name); + setIsExpanded(true); }; - const onSelectAll = (isSelecting = true) => setSelectedRepoNames(isSelecting ? repositories.map((r) => r.name) : []); - const allRowsSelected = selectedRepoNames.length === repositories.length; - const isRepoSelected = (repo: Repository) => selectedRepoNames.includes(repo.name); - - const [rowClicked, setRowClicked] = React.useState('Node 1'); - const isRowClicked = (repo: Repository) => rowClicked === repo.name; const defaultActions: IAction[] = [ { @@ -155,8 +147,6 @@ export const TablesAndTabs = () => { const shouldFocus = [ArrowDown, ArrowUp, Enter, Space].includes(event.key); if (shouldToggle) { - event.preventDefault(); - event.stopPropagation(); onToggle(event); } @@ -167,6 +157,11 @@ export const TablesAndTabs = () => { } }; + const handleDrawerClose = () => { + setIsExpanded(false); + setSelectedRepoName(''); + }; + const customActionsToggle = (props: CustomActionsToggleProps, toggleName: string) => ( { - @@ -249,29 +239,21 @@ export const TablesAndTabs = () => { {repositories.map((repo, rowIndex) => ( - { - if ((event?.target as HTMLInputElement).type !== 'checkbox') { - setRowClicked(rowClicked === repo.name ? '' : repo.name); - setIsExpanded(!isRowClicked(repo)); - } - }} - isHoverable - isRowSelected={repo.name === rowClicked} - > +
onSelectAll(isSelecting), - isSelected: allRowsSelected - }} - /> + {columnNames.name} {columnNames.branches} {columnNames.prs}
setRepoSelected(event, repo, isSelected), - isSelected: isRepoSelected(repo) + onSelect: (event) => setRepoSelected(event, repo), + isSelected: isRepoSelected(repo), + variant: 'radio' }} /> {repo.name}
- siemur/test-space + {/** Preventing default behavior for demo purposes only */} + event.preventDefault()} href="#">siemur/test-space
@@ -316,21 +298,17 @@ export const TablesAndTabs = () => { - { - setRowClicked(''); - setIsExpanded(false); - }} - /> + - {rowClicked} + {selectedRepoName} - siemur/test-space + {/** Preventing default behavior for demo purposes only */} + event.preventDefault()} href="#">siemur/test-space