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 2 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
7 changes: 7 additions & 0 deletions src/components/table/_table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,10 @@
max-height: 1000px;
}
}

.euiTableRow-isClickable {
&:focus {
outline: solid 3px transparentize($euiColorPrimary, .9);
Copy link
Contributor

@cchaos cchaos Sep 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a specific reason why an outline was added? The background color is already changing and the outline (which goes outside of the row borders) makes the coloring look a bit messy. I'd stick to one or the other.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope I didn't even think about it -- just copied what we had from somewhere else! Which one do you think we should go with?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I played around with it some and because of the row borders, the focus ring doesn't look so good, but I would like to adjust the hover color for clickable rows as well, so the best I came up with was:

.euiTableRow-isClickable {
  &:hover {
    background-color: transparentize($euiColorPrimary, .95);
  }

  &:focus {
    background-color: transparentize($euiColorPrimary, .9);
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I like what you did there. This gibes with @chandlerprall's comment too. Will update.

background-color: 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