Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make EuiBasicTable rows keyboard-accessible when they are clickable. #1206

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Fixed issue with unselected tabs and aria-controls attribute in EuiTabbedContent
- Added `tag` icon ([#1188](https://github.com/elastic/eui/pull/1188))
- Replaced `logging` app icon ([#1194](https://github.com/elastic/eui/pull/1194))
- Made `EuiBasicTable` rows keyboard-accessibile when they are clickable ([#1206](https://github.com/elastic/eui/pull/1206))

**Bug fixes**

Expand Down
180 changes: 96 additions & 84 deletions src/components/basic_table/__snapshots__/basic_table.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -473,59 +473,65 @@ exports[`EuiBasicTable rowProps renders rows with custom props from a callback 1
<React.Fragment
key="row_0"
>
<EuiTableRow
className="customRowClass"
data-test-subj="row-1"
isSelected={false}
onClick={[Function]}
>
<EuiTableRowCell
align="left"
header="Name"
key="_data_column_name_0_0"
textOnly={true}
<EuiKeyboardAccessible>
<EuiTableRow
className="customRowClass"
data-test-subj="row-1"
isSelected={false}
onClick={[Function]}
>
name1
</EuiTableRowCell>
</EuiTableRow>
<EuiTableRowCell
align="left"
header="Name"
key="_data_column_name_0_0"
textOnly={true}
>
name1
</EuiTableRowCell>
</EuiTableRow>
</EuiKeyboardAccessible>
</React.Fragment>
<React.Fragment
key="row_1"
>
<EuiTableRow
className="customRowClass"
data-test-subj="row-2"
isSelected={false}
onClick={[Function]}
>
<EuiTableRowCell
align="left"
header="Name"
key="_data_column_name_1_0"
textOnly={true}
<EuiKeyboardAccessible>
<EuiTableRow
className="customRowClass"
data-test-subj="row-2"
isSelected={false}
onClick={[Function]}
>
name2
</EuiTableRowCell>
</EuiTableRow>
<EuiTableRowCell
align="left"
header="Name"
key="_data_column_name_1_0"
textOnly={true}
>
name2
</EuiTableRowCell>
</EuiTableRow>
</EuiKeyboardAccessible>
</React.Fragment>
<React.Fragment
key="row_2"
>
<EuiTableRow
className="customRowClass"
data-test-subj="row-3"
isSelected={false}
onClick={[Function]}
>
<EuiTableRowCell
align="left"
header="Name"
key="_data_column_name_2_0"
textOnly={true}
<EuiKeyboardAccessible>
<EuiTableRow
className="customRowClass"
data-test-subj="row-3"
isSelected={false}
onClick={[Function]}
>
name3
</EuiTableRowCell>
</EuiTableRow>
<EuiTableRowCell
align="left"
header="Name"
key="_data_column_name_2_0"
textOnly={true}
>
name3
</EuiTableRowCell>
</EuiTableRow>
</EuiKeyboardAccessible>
</React.Fragment>
</EuiTableBody>
</EuiTable>
Expand Down Expand Up @@ -567,59 +573,65 @@ exports[`EuiBasicTable rowProps renders rows with custom props from an object 1`
<React.Fragment
key="row_0"
>
<EuiTableRow
className="customClass"
data-test-subj="row"
isSelected={false}
onClick={[Function]}
>
<EuiTableRowCell
align="left"
header="Name"
key="_data_column_name_0_0"
textOnly={true}
<EuiKeyboardAccessible>
<EuiTableRow
className="customClass"
data-test-subj="row"
isSelected={false}
onClick={[Function]}
>
name1
</EuiTableRowCell>
</EuiTableRow>
<EuiTableRowCell
align="left"
header="Name"
key="_data_column_name_0_0"
textOnly={true}
>
name1
</EuiTableRowCell>
</EuiTableRow>
</EuiKeyboardAccessible>
</React.Fragment>
<React.Fragment
key="row_1"
>
<EuiTableRow
className="customClass"
data-test-subj="row"
isSelected={false}
onClick={[Function]}
>
<EuiTableRowCell
align="left"
header="Name"
key="_data_column_name_1_0"
textOnly={true}
<EuiKeyboardAccessible>
<EuiTableRow
className="customClass"
data-test-subj="row"
isSelected={false}
onClick={[Function]}
>
name2
</EuiTableRowCell>
</EuiTableRow>
<EuiTableRowCell
align="left"
header="Name"
key="_data_column_name_1_0"
textOnly={true}
>
name2
</EuiTableRowCell>
</EuiTableRow>
</EuiKeyboardAccessible>
</React.Fragment>
<React.Fragment
key="row_2"
>
<EuiTableRow
className="customClass"
data-test-subj="row"
isSelected={false}
onClick={[Function]}
>
<EuiTableRowCell
align="left"
header="Name"
key="_data_column_name_2_0"
textOnly={true}
<EuiKeyboardAccessible>
<EuiTableRow
className="customClass"
data-test-subj="row"
isSelected={false}
onClick={[Function]}
>
name3
</EuiTableRowCell>
</EuiTableRow>
<EuiTableRowCell
align="left"
header="Name"
key="_data_column_name_2_0"
textOnly={true}
>
name3
</EuiTableRowCell>
</EuiTableRow>
</EuiKeyboardAccessible>
</React.Fragment>
</EuiTableBody>
</EuiTable>
Expand Down
28 changes: 17 additions & 11 deletions src/components/basic_table/basic_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { LoadingTableBody } from './loading_table_body';
import { EuiTableHeaderMobile } from '../table/mobile/table_header_mobile';
import { EuiTableSortMobile } from '../table/mobile/table_sort_mobile';
import { withRequiredProp } from '../../utils/prop_types/with_required_prop';
import { EuiScreenReaderOnly } from '../accessibility';
import { EuiScreenReaderOnly, EuiKeyboardAccessible } from '../accessibility';

const dataTypesProfiles = {
auto: {
Expand Down Expand Up @@ -609,19 +609,25 @@ export class EuiBasicTable extends Component {

const { rowProps: rowPropsCallback } = this.props;
const rowProps = getRowProps(item, rowPropsCallback);
const row = (
<EuiTableRow
aria-owns={expandedRowId}
isSelectable={isSelectable == null ? calculatedHasSelection : isSelectable}
isSelected={selected}
hasActions={hasActions == null ? calculatedHasActions : hasActions}
isExpandable={isExpandable}
{...rowProps}
>
{cells}
</EuiTableRow>
);

return (
<Fragment key={`row_${itemId}`}>
<EuiTableRow
aria-owns={expandedRowId}
isSelectable={isSelectable == null ? calculatedHasSelection : isSelectable}
isSelected={selected}
hasActions={hasActions == null ? calculatedHasActions : hasActions}
isExpandable={isExpandable}
{...rowProps}
>
{cells}
</EuiTableRow>
{rowProps.onClick
? <EuiKeyboardAccessible>{row}</EuiKeyboardAccessible>
: row
}
{expandedRow}
</Fragment>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/flex/_flex_item.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
.euiFlexItem {
display: flex; /* 1 */
flex-direction: column; /* 1 */

@include internetExplorerOnly {
min-width: 1px; /* 2 */
}
Expand Down
10 changes: 10 additions & 0 deletions src/components/table/_table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,13 @@
max-height: 1000px;
}
}

.euiTableRow-isClickable {
&:hover {
background-color: $euiTableHoverClickableColor;
}

&:focus {
background-color: $euiTableFocusClickableColor;
}
}
2 changes: 2 additions & 0 deletions src/components/table/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ $euiTableHoverColor: tintOrShade($euiColorLightestShade, 50%, 20%);
$euiTableSelectedColor: tintOrShade($euiFocusBackgroundColor, 30%, 0%);
$euiTableHoverSelectedColor: tintOrShade($euiFocusBackgroundColor, 0, 10%);
$euiTableActionsBorderColor: transparentize($euiColorMediumShade, .9);
$euiTableHoverClickableColor: transparentize($euiColorPrimary, .95);
$euiTableFocusClickableColor: transparentize($euiColorPrimary, .9);
3 changes: 3 additions & 0 deletions src/components/table/table_row.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const EuiTableRow = ({
hasActions,
isExpandedRow,
isExpandable,
onClick,
...rest
}) => {
const classes = classNames('euiTableRow', className, {
Expand All @@ -18,11 +19,13 @@ export const EuiTableRow = ({
'euiTableRow-hasActions': hasActions,
'euiTableRow-isExpandedRow': isExpandedRow,
'euiTableRow-isExpandable': isExpandable,
'euiTableRow-isClickable': onClick,
});

return (
<tr
className={classes}
onClick={onClick}
{...rest}
>
{children}
Expand Down