Skip to content

Commit

Permalink
allow default TableRow keypress events (#221) (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustAboutJeff authored and jeroenransijn committed Aug 13, 2018
1 parent 5ddaa47 commit 4563c27
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/table/src/TableRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,21 @@ export default class TableRow extends PureComponent {
}
}

onRef = node => {
this.node = node
}

handleKeyPress = e => {
if (this.props.isSelectable) {
if (e.key === 'Enter' || e.key === ' ') {
this.props.onSelect()
e.preventDefault()

// NOTE: In scenarios where the target for key press is our
// tabIndex <Pane> below, prevent the default event action
// so that browser scroll will not occur.
if (e.target === this.node) {
e.preventDefault()
}
}
}

Expand All @@ -83,6 +93,7 @@ export default class TableRow extends PureComponent {

return (
<Pane
innerRef={this.onRef}
display="flex"
{...(isSelectable
? {
Expand Down
11 changes: 11 additions & 0 deletions src/table/stories/index.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ storiesOf('table', module)
<TableRow>TableRow</TableRow>
</Box>
))
.add('TableRow isSelectable with nested UI', () => (
<Box padding={40}>
{(() => {
document.body.style.margin = '0'
document.body.style.height = '100vh'
})()}
<TableRow isSelectable>
<input type="text" placeholder="type a space" />
</TableRow>
</Box>
))
.add('TableHeaderCell', () => (
<Box padding={40}>
{(() => {
Expand Down

0 comments on commit 4563c27

Please sign in to comment.