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
Cell auto focus property #2123
Merged
Merged
Cell auto focus property #2123
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,6 +149,11 @@ const propTypes = { | |
* With this property the height of the cell will grow to fit the cell content. | ||
*/ | ||
rowMinimumHeight: PropTypes.string, | ||
|
||
/** | ||
* Determines if focus is moved to the interactive element of a cell when a single button or hyperlink element is the only interactive element. | ||
*/ | ||
isAutoFocusEnabled: PropTypes.bool, | ||
}; | ||
|
||
const defaultProps = { | ||
|
@@ -186,6 +191,7 @@ const DataGrid = forwardRef((props, ref) => { | |
rows, | ||
sections, | ||
rowMinimumHeight, | ||
isAutoFocusEnabled, | ||
} = props; | ||
|
||
const displayedColumns = (hasSelectableRows ? [WorklistDataGridUtils.ROW_SELECTION_COLUMN] : []).concat(pinnedColumns).concat(overflowColumns); | ||
|
@@ -228,7 +234,8 @@ const DataGrid = forwardRef((props, ref) => { | |
setCellAriaLiveMessage, | ||
tableRef: grid, | ||
tableContainerRef, | ||
}), [grid, tableContainerRef]); | ||
isAutoFocusEnabled, | ||
}), [grid, isAutoFocusEnabled, tableContainerRef]); | ||
|
||
// ------------------------------------- | ||
// functions | ||
|
@@ -282,7 +289,7 @@ const DataGrid = forwardRef((props, ref) => { | |
|
||
// Set focus to a single header button or hyperlink if they are the only content in cell | ||
const cellButtonOrHyperlink = focusedCell.querySelector('a, button'); | ||
if ((isHeaderRow && !focusedCell.hasAttribute('tabindex')) || cellButtonOrHyperlink) { | ||
if ((isHeaderRow && !focusedCell.hasAttribute('tabindex')) || (isAutoFocusEnabled && cellButtonOrHyperlink)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will action buttons on header cells still be autofocused, regardless of the prop? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The first half of the condition is for the header row and all unit tests pass. I will manually confirm though. Yes, the button in the row header is still being selected. |
||
focusedCell = focusedCell.querySelector('a, button, [role="button"]'); | ||
focusedCell?.focus(); | ||
return; | ||
|
@@ -297,7 +304,7 @@ const DataGrid = forwardRef((props, ref) => { | |
} | ||
|
||
focusedCell?.focus(); | ||
}, [displayedColumns, isSection, isRowSelectionCell, hasColumnHeaderActions]); | ||
}, [displayedColumns, isSection, hasColumnHeaderActions, isAutoFocusEnabled, isRowSelectionCell]); | ||
|
||
// The focus is handled by the DataGrid. However, there are times | ||
// when the other components may want to change the currently focus | ||
|
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
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
19 changes: 19 additions & 0 deletions
19
...ta-grid/WorklistDataGrid.1/Examples.3/WorklistDataGridAutoFocusableCell.doc.mdx
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,19 @@ | ||
import WorklistDataGridAutoFocusableCell from './WorklistDataGridAutoFocusableCell?dev-site-example'; | ||
|
||
# Auto Focusable Cell Navigation | ||
|
||
### Description | ||
|
||
The content of a cell in the [Worklist Data Grid](/components/cerner-terra-framework-docs/data-grid/worklist-data-grid/about) may be empty, text, numerical, or any combination of widgets. | ||
When the only interactable element in the cell is a button or hyperlink element and the isAutoFocusable property is set to true, navigation to the cell will focus the button or hyperlink element directly. | ||
|
||
|
||
#### Keyboard Interactions | ||
|
||
|Key Interaction|Description| | ||
|-|-| | ||
|*Enter*|Moves focus to the button or hyperlink element when the table cell has focus.| | ||
|*Escape*|Moves focus to the parent table cell element.| | ||
|
||
|
||
<WorklistDataGridAutoFocusableCell /> |
69 changes: 69 additions & 0 deletions
69
...ev-site/doc/data-grid/WorklistDataGrid.1/Examples.3/WorklistDataGridAutoFocusableCell.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,69 @@ | ||
import React, { useState } from 'react'; | ||
import { WorklistDataGrid } from 'terra-data-grid'; | ||
import NotificationDialog from 'terra-notification-dialog'; | ||
|
||
const WorklistDataGridAutoFocusableCell = () => { | ||
const rowHeaderIndex = 0; | ||
|
||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
const handleCloseModal = () => { | ||
setIsOpen(false); | ||
}; | ||
|
||
const handleButtonOpenModal = () => { | ||
setIsOpen(true); | ||
}; | ||
|
||
const buttonCell = <button type="button" aria-label="Alert" onClick={handleButtonOpenModal}>Alert</button>; | ||
// eslint-disable-next-line react/forbid-dom-props | ||
const anchorCell = <a href="https://www.oracle.com/" aria-label="Visit Oracle">Visit Oracle</a>; | ||
|
||
const gridDataJSON = { | ||
cols: [ | ||
{ id: 'Column-0', displayName: 'Patient' }, | ||
{ id: 'Column-1', displayName: 'Action A' }, | ||
{ id: 'Column-2', displayName: 'Action B' }, | ||
], | ||
rows: [ | ||
{ | ||
id: '1', | ||
cells: [ | ||
{ content: 'Fleck, Arthur' }, | ||
{ content: buttonCell }, | ||
{ content: anchorCell }, | ||
], | ||
}, | ||
], | ||
}; | ||
|
||
const { cols, rows } = gridDataJSON; | ||
|
||
return ( | ||
<> | ||
{isOpen && ( | ||
<NotificationDialog | ||
variant="hazard-low" | ||
dialogTitle="Button from Focusable Cell" | ||
startMessage="Button Selected" | ||
acceptAction={{ | ||
text: 'OK', | ||
onClick: handleCloseModal, | ||
}} | ||
/> | ||
)} | ||
<WorklistDataGrid | ||
id="default-terra-worklist-data-grid-focusable-cell" | ||
overflowColumns={cols} | ||
defaultColumnWidth={170} | ||
rows={rows} | ||
rowHeaderIndex={rowHeaderIndex} | ||
rowHeight="50px" | ||
ariaLabel="Worklist Data Grid" | ||
isAutoFocusEnabled | ||
/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like this example is missing |
||
</> | ||
); | ||
}; | ||
|
||
export default WorklistDataGridAutoFocusableCell; |
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would
enableAutofocus
make sense as a simpler name?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to follow the naming pattern of some of the other props. However, I can make this change if it is the desired update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the
is___
pattern is preferred. Would a name likeisAutofocusable
or similar work? (Not sure if that's sufficiently descriptive of the prop's usage though)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're keeping to the
is__
pattern, then I think both these names are similar enough that either works.