Skip to content

Commit

Permalink
feat(DataTable): option to show overflow menu on hover
Browse files Browse the repository at this point in the history
This change introduces `overflowMenuOnHover` prop to `<DataTable>` that
determines whether or not to show overflow menu on hover, by changing
CSS class of `<Table>` as follows:

* `overflowMenuOnHover={true}` _unsets_
  `bx--data-table--visible-overflow-menu`
* `overflowMenuOnHover={false}` _sets_
  `bx--data-table--visible-overflow-menu`

That CSS class changes the behavior of overflow menu in
`<TableCell className="bx--table-column-menu">`; The former above shows
overflow menu only on hover, the latter above shows overflow menu
always.

Though our latest design dictates that showing overflow menu on hover
should be optional, this change sets `overflowMenuOnHover={true}` as the
default. This is because of the following reasons:

1. `<DataTable>` has never set `bx--data-table--visible-overflow-menu`
   before and thus setting it by default will be a breaking change
2. Showing overflow menu always can alternately be (and has been in our
   stories) achieved by _not_ setting
   `className="bx--table-column-menu"` to `<TableCell>`

Fixes carbon-design-system#5804.
  • Loading branch information
asudoh committed Apr 8, 2020
1 parent 2c33584 commit 381ae6b
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 2 deletions.
12 changes: 12 additions & 0 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ Map {
"Table": Object {
"defaultProps": Object {
"isSortable": false,
"overflowMenuOnHover": true,
},
"propTypes": Object {
"className": Object {
Expand All @@ -747,6 +748,9 @@ Map {
"isSortable": Object {
"type": "bool",
},
"overflowMenuOnHover": Object {
"type": "bool",
},
"shouldShowBorder": Object {
"type": "bool",
},
Expand Down Expand Up @@ -1216,6 +1220,7 @@ Map {
"defaultProps": Object {
"filterRows": [Function],
"locale": "en",
"overflowMenuOnHover": true,
"size": "normal",
"sortRow": [Function],
"translateWithId": [Function],
Expand Down Expand Up @@ -1251,6 +1256,9 @@ Map {
"locale": Object {
"type": "string",
},
"overflowMenuOnHover": Object {
"type": "bool",
},
"radio": Object {
"type": "bool",
},
Expand Down Expand Up @@ -1315,6 +1323,7 @@ Map {
"Table" => Object {
"defaultProps": Object {
"isSortable": false,
"overflowMenuOnHover": true,
},
"propTypes": Object {
"className": Object {
Expand All @@ -1323,6 +1332,9 @@ Map {
"isSortable": Object {
"type": "bool",
},
"overflowMenuOnHover": Object {
"type": "bool",
},
"shouldShowBorder": Object {
"type": "bool",
},
Expand Down
8 changes: 7 additions & 1 deletion packages/react/src/components/DataTable/DataTable-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,13 @@ storiesOf('DataTable', module)
.add(
'with overflow menu',
withReadme(readme, () =>
require('./stories/with-overflow-menu').default(props())
require('./stories/with-overflow-menu').default({
...props(),
overflowMenuOnHover: boolean(
'Show overflow menu on hover (overflowMenuOnHover)',
false
),
})
),
{
info: {
Expand Down
8 changes: 8 additions & 0 deletions packages/react/src/components/DataTable/DataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,19 @@ export default class DataTable extends React.Component {
* Specify whether the table should be able to be sorted by its headers
*/
isSortable: PropTypes.bool,

/**
* Specify whether the overflow menu (if it exists) should be shown always, or only on hover
*/
overflowMenuOnHover: PropTypes.bool,
};

static defaultProps = {
sortRow: defaultSortRow,
filterRows: defaultFilterRows,
locale: 'en',
size: 'normal',
overflowMenuOnHover: true,
translateWithId,
};

Expand Down Expand Up @@ -365,6 +371,7 @@ export default class DataTable extends React.Component {
useStaticWidth,
shouldShowBorder,
stickyHeader,
overflowMenuOnHover,
} = this.props;
return {
useZebraStyles,
Expand All @@ -373,6 +380,7 @@ export default class DataTable extends React.Component {
useStaticWidth,
shouldShowBorder,
stickyHeader,
overflowMenuOnHover,
};
};

Expand Down
8 changes: 8 additions & 0 deletions packages/react/src/components/DataTable/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const Table = ({
useStaticWidth,
shouldShowBorder,
stickyHeader,
overflowMenuOnHover,
...other
}) => {
const componentClass = cx(`${prefix}--data-table`, className, {
Expand All @@ -32,6 +33,7 @@ export const Table = ({
[`${prefix}--data-table--static`]: useStaticWidth,
[`${prefix}--data-table--no-border`]: !shouldShowBorder,
[`${prefix}--data-table--sticky-header`]: stickyHeader,
[`${prefix}--data-table--visible-overflow-menu`]: !overflowMenuOnHover,
});
const table = (
<table {...other} className={componentClass}>
Expand Down Expand Up @@ -79,10 +81,16 @@ Table.propTypes = {
* `false` If true, will keep the header sticky (only data rows will scroll)
*/
stickyHeader: PropTypes.bool,

/**
* Specify whether the overflow menu (if it exists) should be shown always, or only on hover
*/
overflowMenuOnHover: PropTypes.bool,
};

Table.defaultProps = {
isSortable: false,
overflowMenuOnHover: true,
};

export default Table;
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ exports[`DataTable selection -- radio buttons should not have select-all checkbo
]
}
locale="en"
overflowMenuOnHover={true}
radio={true}
render={
[MockFunction] {
Expand Down Expand Up @@ -60,6 +61,7 @@ exports[`DataTable selection -- radio buttons should not have select-all checkbo
>
<Table
isSortable={false}
overflowMenuOnHover={true}
>
<TableHead>
<TableRow>
Expand Down Expand Up @@ -119,6 +121,7 @@ exports[`DataTable selection -- radio buttons should not have select-all checkbo
</div>
<Table
isSortable={false}
overflowMenuOnHover={true}
>
<table
className="bx--data-table bx--data-table--no-border"
Expand Down Expand Up @@ -199,6 +202,7 @@ exports[`DataTable selection -- radio buttons should render 1`] = `
]
}
locale="en"
overflowMenuOnHover={true}
radio={true}
render={
[MockFunction] {
Expand Down Expand Up @@ -334,6 +338,7 @@ exports[`DataTable selection -- radio buttons should render 1`] = `
>
<Table
isSortable={false}
overflowMenuOnHover={true}
>
<TableHead>
<TableRow>
Expand Down Expand Up @@ -463,6 +468,7 @@ exports[`DataTable selection -- radio buttons should render 1`] = `
</div>
<Table
isSortable={false}
overflowMenuOnHover={true}
>
<table
className="bx--data-table bx--data-table--no-border"
Expand Down Expand Up @@ -802,6 +808,7 @@ exports[`DataTable selection should have select-all default to un-checked if no
]
}
locale="en"
overflowMenuOnHover={true}
render={
[MockFunction] {
"calls": Array [
Expand Down Expand Up @@ -845,6 +852,7 @@ exports[`DataTable selection should have select-all default to un-checked if no
>
<Table
isSortable={false}
overflowMenuOnHover={true}
>
<TableHead>
<TableRow>
Expand Down Expand Up @@ -912,6 +920,7 @@ exports[`DataTable selection should have select-all default to un-checked if no
</div>
<Table
isSortable={false}
overflowMenuOnHover={true}
>
<table
className="bx--data-table bx--data-table--no-border"
Expand Down Expand Up @@ -1040,6 +1049,7 @@ exports[`DataTable selection should render 1`] = `
]
}
locale="en"
overflowMenuOnHover={true}
render={
[MockFunction] {
"calls": Array [
Expand Down Expand Up @@ -1174,6 +1184,7 @@ exports[`DataTable selection should render 1`] = `
>
<Table
isSortable={false}
overflowMenuOnHover={true}
>
<TableHead>
<TableRow>
Expand Down Expand Up @@ -1311,6 +1322,7 @@ exports[`DataTable selection should render 1`] = `
</div>
<Table
isSortable={false}
overflowMenuOnHover={true}
>
<table
className="bx--data-table bx--data-table--no-border"
Expand Down Expand Up @@ -1647,6 +1659,7 @@ exports[`DataTable should render 1`] = `
]
}
locale="en"
overflowMenuOnHover={true}
render={
[MockFunction] {
"calls": Array [
Expand Down Expand Up @@ -1870,6 +1883,7 @@ exports[`DataTable should render 1`] = `
</TableToolbar>
<Table
isSortable={false}
overflowMenuOnHover={true}
size="normal"
>
<TableHead>
Expand Down Expand Up @@ -2474,6 +2488,7 @@ exports[`DataTable should render 1`] = `
</TableToolbar>
<Table
isSortable={false}
overflowMenuOnHover={true}
size="normal"
>
<table
Expand Down Expand Up @@ -2616,6 +2631,7 @@ exports[`DataTable sticky header should render 1`] = `
]
}
locale="en"
overflowMenuOnHover={true}
render={
[MockFunction] {
"calls": Array [
Expand Down Expand Up @@ -2840,6 +2856,7 @@ exports[`DataTable sticky header should render 1`] = `
</TableToolbar>
<Table
isSortable={false}
overflowMenuOnHover={true}
size="normal"
stickyHeader={true}
>
Expand Down Expand Up @@ -3447,6 +3464,7 @@ exports[`DataTable sticky header should render 1`] = `
</TableToolbar>
<Table
isSortable={false}
overflowMenuOnHover={true}
size="normal"
stickyHeader={true}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports[`DataTable.Table should render 1`] = `
<Table
className="custom-class"
isSortable={false}
overflowMenuOnHover={true}
>
<table
className="bx--data-table custom-class bx--data-table--no-border"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
exports[`DataTable.TableBody should render 1`] = `
<Table
isSortable={false}
overflowMenuOnHover={true}
>
<table
className="bx--data-table bx--data-table--no-border"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
exports[`DataTable.TableCell should render 1`] = `
<Table
isSortable={false}
overflowMenuOnHover={true}
>
<table
className="bx--data-table bx--data-table--no-border"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
exports[`DataTable.TableExpandHeader should render 1`] = `
<Table
isSortable={false}
overflowMenuOnHover={true}
>
<table
className="bx--data-table bx--data-table--no-border"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
exports[`DataTable.TableExpandRow should render 1`] = `
<Table
isSortable={false}
overflowMenuOnHover={true}
>
<table
className="bx--data-table bx--data-table--no-border"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
exports[`DataTable.TableHead should render 1`] = `
<Table
isSortable={false}
overflowMenuOnHover={true}
>
<table
className="bx--data-table bx--data-table--no-border"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
exports[`DataTable.TableHeader should have an active and ascending class if sorting by ASC 1`] = `
<Table
isSortable={false}
overflowMenuOnHover={true}
>
<table
className="bx--data-table bx--data-table--no-border"
Expand Down Expand Up @@ -40,6 +41,7 @@ exports[`DataTable.TableHeader should have an active and ascending class if sort
exports[`DataTable.TableHeader should have an active class if it is the sort header and the sort state is not NONE 1`] = `
<Table
isSortable={false}
overflowMenuOnHover={true}
>
<table
className="bx--data-table bx--data-table--no-border"
Expand Down Expand Up @@ -77,6 +79,7 @@ exports[`DataTable.TableHeader should have an active class if it is the sort hea
exports[`DataTable.TableHeader should render 1`] = `
<Table
isSortable={false}
overflowMenuOnHover={true}
>
<table
className="bx--data-table bx--data-table--no-border"
Expand Down Expand Up @@ -114,6 +117,7 @@ exports[`DataTable.TableHeader should render 1`] = `
exports[`DataTable.TableHeader should render 2`] = `
<Table
isSortable={false}
overflowMenuOnHover={true}
>
<table
className="bx--data-table bx--data-table--no-border"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
exports[`DataTable.TableRow should render 1`] = `
<Table
isSortable={false}
overflowMenuOnHover={true}
>
<table
className="bx--data-table bx--data-table--no-border"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
exports[`DataTable.TableSelectAll should render 1`] = `
<Table
isSortable={false}
overflowMenuOnHover={true}
>
<table
className="bx--data-table bx--data-table--no-border"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
exports[`DataTable.TableSelectRow should render 1`] = `
<Table
isSortable={false}
overflowMenuOnHover={true}
>
<table
className="bx--data-table bx--data-table--no-border"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default props => (
{row.cells.map(cell => (
<TableCell key={cell.id}>{cell.value}</TableCell>
))}
<TableCell>
<TableCell className="bx--table-column-menu">
<OverflowMenu flipped>
<OverflowMenuItem primaryFocus>Action 1</OverflowMenuItem>
<OverflowMenuItem>Action 2</OverflowMenuItem>
Expand Down

0 comments on commit 381ae6b

Please sign in to comment.