Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Commit

Permalink
Merge branch 'wdg_column_resizing' into UXPLATFORM-9611
Browse files Browse the repository at this point in the history
  • Loading branch information
Koushik Kalli authored and Koushik Kalli committed Oct 18, 2023
2 parents 281cf72 + 74fb315 commit e62cca1
Show file tree
Hide file tree
Showing 29 changed files with 122 additions and 22 deletions.
1 change: 1 addition & 0 deletions packages/terra-data-grid/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

* Fixed
* Fixed issue where WorklistDataGrid loses focus when Row Selection Mode is turned off from a Row Selection Cell.
* Fixed issue where focus was moved from editable fields when using key events from data grid components.
* Fixed tab focus management when next element is in a hidden container.
* Fixed tab focus management to wrap to the first focusable element when the data grid is the last focusable element.

Expand Down
31 changes: 29 additions & 2 deletions packages/terra-data-grid/src/DataGrid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const propTypes = {
columnHeaderHeight: PropTypes.string,

/**
* Numeric increment in pixels to adjust column width when resizing via the keyboard
* Numeric increment in pixels to adjust column width when resizing via the keyboard.
*/
columnResizeIncrement: PropTypes.number,

Expand Down Expand Up @@ -392,12 +392,39 @@ const DataGrid = injectIntl((props) => {
}
};

/**
*
* @param {HTMLElement} element - The element to check if it is a text input
* @returns True if the element is a text input. Otherwise, false.
*/
const isTextInput = (element) => {
const { tagName } = element;
if (tagName.toLowerCase() === 'input') {
const validTypes = ['text', 'password', 'number', 'email', 'tel', 'url', 'search', 'date', 'datetime', 'datetime-local', 'time', 'month', 'week'];
const inputType = element.type;
return validTypes.indexOf(inputType) >= 0;
}

return false;
};

const handleKeyDown = (event) => {
const cellCoordinates = { row: focusedRow, col: focusedCol };
let nextRow = cellCoordinates.row;
let nextCol = cellCoordinates.col;
setCheckResizable(false);

const targetElement = event.target;

// Allow default behavior if the event target is an editable field

Check failure on line 420 in packages/terra-data-grid/src/DataGrid.jsx

View workflow job for this annotation

GitHub Actions / build

Trailing spaces not allowed
if (event.keyCode !== KeyCode.KEY_TAB
&& (isTextInput(targetElement)
|| ['textarea', 'select'].indexOf(targetElement.tagName.toLowerCase()) >= 0
|| (targetElement.hasAttribute('contentEditable') && targetElement.getAttribute('contentEditable') !== false))) {
return;
}

const key = event.keyCode;
switch (key) {
case KeyCode.KEY_UP:
Expand Down Expand Up @@ -592,7 +619,7 @@ const DataGrid = injectIntl((props) => {
columnResizeIncrement={columnResizeIncrement}
onColumnSelect={handleColumnSelect}
onResizeMouseDown={onResizeMouseDown}
onResizeHandleChange={onResizeHandleChange}
onResizeHandleChange={onColumnResize ? onResizeHandleChange: null}

Check failure on line 622 in packages/terra-data-grid/src/DataGrid.jsx

View workflow job for this annotation

GitHub Actions / build

Operator ':' must be spaced
/>
<tbody>
{rows.map((row, index) => (
Expand Down
6 changes: 3 additions & 3 deletions packages/terra-data-grid/src/subcomponents/ColumnHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ const propTypes = {
*/
activeColumnIndex: PropTypes.number,
/**
* Specifies if resize handle should be active
* Specifies if resize handle should be active.
*/
activeColumnResizing: PropTypes.bool,
/**
* Numeric increment in pixels to adjust column width when resizing via the keyboard
* Numeric increment in pixels to adjust column width when resizing via the keyboard.
*/
columnResizeIncrement: PropTypes.number,
/**
Expand All @@ -40,7 +40,7 @@ const propTypes = {
*/
onResizeMouseDown: PropTypes.func,
/**
* Function that is called when the the keyboard is used to adjust the column size
* Function that is called when the the keyboard is used to adjust the column size.
*/
onResizeHandleChange: PropTypes.func,
};
Expand Down
12 changes: 5 additions & 7 deletions packages/terra-data-grid/src/subcomponents/ColumnHeaderCell.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const propTypes = {
maximumWidth: PropTypes.number,

/**
* Boolean value indictating whether or not the header cell is focused
* Boolean value indicating whether or not the header cell is focused.
*/
isActive: PropTypes.bool,

Expand All @@ -77,7 +77,7 @@ const propTypes = {
isResizeActive: PropTypes.bool,

/**
* Numeric increment in pixels to adjust column width when resizing via the keyboard
* Numeric increment in pixels to adjust column width when resizing via the keyboard.
*/
columnResizeIncrement: PropTypes.number,

Expand Down Expand Up @@ -114,7 +114,7 @@ const propTypes = {
onResizeMouseDown: PropTypes.func,

/**
* Function that is called when the the keyboard is used to adjust the column size
* Function that is called when the the keyboard is used to adjust the column size.
*/
onResizeHandleChange: PropTypes.func,

Expand Down Expand Up @@ -164,10 +164,8 @@ const ColumnHeaderCell = (props) => {
const [isResizeHandleActive, setResizeHandleActive] = useState(false);

useEffect(() => {
if (isActive) {
if (isResizeActive) {
if (isActive && isResizeActive) {
setResizeHandleActive(true);

Check failure on line 168 in packages/terra-data-grid/src/subcomponents/ColumnHeaderCell.jsx

View workflow job for this annotation

GitHub Actions / build

Expected indentation of 6 spaces but found 8
}
} else {
setResizeHandleActive(false);
}
Expand Down Expand Up @@ -207,7 +205,6 @@ const ColumnHeaderCell = (props) => {
if (isResizable && isResizeHandleActive) {
columnHeaderCellButtonRef.current.focus();
setResizeHandleActive(false);

event.stopPropagation();
event.preventDefault();
}
Expand Down Expand Up @@ -281,6 +278,7 @@ const ColumnHeaderCell = (props) => {
columnWidth={width}
columnResizeIncrement={columnResizeIncrement}
isActive={isResizeHandleActive}
setIsActive={setResizeHandleActive}
height={tableHeight}
minimumWidth={minimumWidth}
maximumWidth={maximumWidth}
Expand Down
27 changes: 20 additions & 7 deletions packages/terra-data-grid/src/subcomponents/ColumnResizeHandle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@ const propTypes = {
*/
height: PropTypes.number.isRequired,
/**
* Numeric increment in pixels to adjust column width when resizing via the keyboard
* Numeric increment in pixels to adjust column width when resizing via the keyboard.
*/
columnResizeIncrement: PropTypes.number,
/**
* Control is the active element
*/
isActive: PropTypes.bool,
/**

Check failure on line 40 in packages/terra-data-grid/src/subcomponents/ColumnResizeHandle.jsx

View workflow job for this annotation

GitHub Actions / build

Expected indentation of 2 spaces but found 4
* Callback to update isActive for parent.
*/
setIsActive: PropTypes.func,
/**
* Number that specifies the minimum column width in pixels.
*/
Expand All @@ -50,13 +54,19 @@ const propTypes = {
*/
onResizeMouseDown: PropTypes.func.isRequired,
/**
* Function that is called when onMouseDown event is triggered for the resize handle
* Function that is called when onMouseDown event is triggered for the resize handle.
*/
onResizeMouseUp: PropTypes.func.isRequired,
/**
* Function that is called when the the keyboard is used to adjust the column size
* Function that is called when the the keyboard is used to adjust the column size.
*/
onResizeHandleChange: PropTypes.func,

/**
* Function that is called when the the keyboard is used to adjust the column size.
*/
onResizeHandleBlur: PropTypes.func,

/**
* @private
* The intl object containing translations. This is retrieved from the context automatically by injectIntl.
Expand All @@ -71,17 +81,19 @@ const defaultProps = {
const ColumnResizeHandle = (props) => {
const {
columnIndex,
columnResizeIncrement,
columnText,
columnWidth,
height,
columnResizeIncrement,
intl,
isActive,
minimumWidth,
maximumWidth,
minimumWidth,
onResizeHandleBlur,

Check failure on line 92 in packages/terra-data-grid/src/subcomponents/ColumnResizeHandle.jsx

View workflow job for this annotation

GitHub Actions / build

'onResizeHandleBlur' is assigned a value but never used
onResizeHandleChange,
onResizeMouseDown,
onResizeMouseUp,
onResizeHandleChange,
intl,
setIsActive

Check failure on line 96 in packages/terra-data-grid/src/subcomponents/ColumnResizeHandle.jsx

View workflow job for this annotation

GitHub Actions / build

Missing trailing comma
} = props;

// Retrieve current theme from context
Expand Down Expand Up @@ -187,6 +199,7 @@ const ColumnResizeHandle = (props) => {
const onBlur = () => {
setNavigationEnabled(true);
setIsAriaLabel(false);
setIsActive(false);
};

return (
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions packages/terra-data-grid/tests/wdio/data-grid-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,35 @@ Terra.describeViewports('DataGrid', ['medium', 'large'], () => {
Terra.validates.element('focusable-textarea-cell-trap-focus', { columnResizeSelector });
expect(browser.$$('textarea:focus')).toBeElementsArrayOfSize(1);
});

it('validates that keyboard inputs will not move focus from an input field', () => {
browser.$('#input-cell').click();

browser.keys(['ArrowRight', 'ArrowLeft']);

Terra.validates.element('data-grid-focusable-input-retains-focus', { columnResizeSelector });
expect(browser.$('#input-cell').isFocused()).toBe(true);
});

it('validates that keyboard inputs will not move focus from a textarea', () => {
browser.$('#textarea-cell').click();

browser.pause(250);

browser.keys(['ArrowRight', 'ArrowLeft']);

Terra.validates.element('data-grid-focusable-textarea-retains-focus', { columnResizeSelector });
expect(browser.$('#textarea-cell').isFocused()).toBe(true);
});

it('validates that keyboard inputs will not move focus from a select element', () => {
browser.$('#specialties').click();

browser.keys(['ArrowRight', 'ArrowLeft']);

Terra.validates.element('data-grid-focusable-select-retains-focus', { columnResizeSelector });
expect(browser.$('#specialties').isFocused()).toBe(true);
});
});

describe('with pinned columns', () => {
Expand Down
5 changes: 5 additions & 0 deletions packages/terra-framework-docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

## Unreleased

* Changed
* Updated `terra-menu` examples with focus highlight styles for terra-button on closing menu with selection of menu-item.

* Updated
* Updates examples for `terra-data-grid` to cover scenarios for focusable elements prevented from receiving focus.
* Updated focusable cell test for `terra-data-grid` to account for focusable elements in a hidden container.

## 1.40.0 - (October 11, 2023)
Expand All @@ -19,6 +23,7 @@

* Updated
* Updated examples for `terra-collapsible-menu-view` to use more meaningful controls and control labels.
* Updated focusable cell test for `terra-data-grid` to account for focusable elements in a hidden container.
* Updated examples and tests to add support for content scrolling within the iframe.
* Updated examples and tests for `terra-embedded-content-consumer` to show the preferred way to set the title.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
// Themes
@import '../../../theme/clinical-lowlight-theme/BasicMenu.module';
@import '../../../theme/orion-fusion-theme/BasicMenu.module';

:local {
.menu-wrapper {
display: inline-block;

button {
&:focus {
box-shadow: var(--terra-framework-docs-menu-button-focus-box-shadow, 0 0 1px 3px rgba(76, 178, 233, 0.5), 0 0 7px 4px rgba(76, 178, 233, 0.35));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ const DataGridFocusableCell = () => {

const buttonCell = <button type="button" aria-label="Alert" onClick={handleButtonOpenModal}>Alert</button>;
// eslint-disable-next-line react/forbid-dom-props
const inputCell = <input type="text" aria-label="Text Input" style={{ width: '100px', height: '25px', display: 'inline' }} />;
const inputCell = <input id="input-cell" type="text" aria-label="Text Input" style={{ width: '100px', height: '25px', display: 'inline' }} />;
const inputCell2 = <input type="text" aria-label="Text Input" style={{ width: '100px', height: '25px', display: 'inline' }} />;
const anchorCell = <a href="https://www.oracle.com/" aria-label="Visit Oracle">Visit Oracle</a>;
const textAreaCell = <textarea name="textArea" aria-label="Text Area" rows="1" cols="15" value="Text Area" />;
const textAreaCell = <textarea id="textarea-cell" name="textArea" aria-label="Text Area" rows="1" cols="15" value="Text Area" />;
const selectCell = (
<select name="specialties" id="specialties" aria-label="Select Specialty">
<option value="ambulatory">Ambulatory</option>
Expand Down Expand Up @@ -54,7 +55,7 @@ const DataGridFocusableCell = () => {
{
content: (<div>
{buttonCell}
{inputCell}
{inputCell2}
{/* eslint-disable-next-line react/jsx-closing-tag-location */}
</div>),
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
:local {
.clinical-lowlight-theme {
/* ---------------------------------------------------------------------- *
* Menu: Doc Examples
* ---------------------------------------------------------------------- */
--terra-framework-docs-menu-button-focus-box-shadow: 0 0 1px 3px #004c76, 0 0 7px 4px #004c76;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
:local {
.orion-fusion-theme {
/* ---------------------------------------------------------------------- *
* Menu: Doc Examples
* ---------------------------------------------------------------------- */
--terra-framework-docs-menu-button-focus-box-shadow: 0 0 1px 3px rgba(76, 178, 233, 0.5), 0 0 7px 4px rgba(76, 178, 233, 0.35);
}
}

0 comments on commit e62cca1

Please sign in to comment.