Skip to content

Commit

Permalink
#6913: grid cards keyboard navigation (#10150)
Browse files Browse the repository at this point in the history
Makes grid cards keyboard navigable and accessible again

On Behalf of DB Systel

Co-authored-by: Florian Kellner <florian.fl.kellner@deutschebahn.com>
  • Loading branch information
fkellner and Florian Kellner committed Jul 4, 2024
1 parent b369af2 commit 608d54d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
6 changes: 5 additions & 1 deletion web/client/components/misc/GridCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ class GridCard extends React.Component {
return (<div
style={this.props.style}
className={"gridcard" + (this.props.className ? " " + this.props.className : "")}
onClick={this.props.onClick}>
onClick={this.props.onClick}
role={this.props.onClick ? "link" : ""}
tabIndex={0}
onKeyDown={(e) => e.key === 'Enter' ? this.props.onClick(e) : null}
>
{!isNil(this.props.header) ? <div style={this.props.titleStyle} className="gridcard-title bg-primary">{this.props.header}</div> : null}
{this.props.children}
{this.renderActions()}
Expand Down
9 changes: 9 additions & 0 deletions web/client/components/misc/__tests__/GridCard-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,13 @@ describe('This test for GridCard', () => {
);
expect(button).toExist();
});

it('enter triggers onClick event', (done) => {
const container = document.getElementById('container');
const testName = "test";
const testDescription = "testDescription";
ReactDOM.render(
<GridCard header={testName} onClick={() => {done();}}>{testDescription}</GridCard>, container);
TestUtils.Simulate.keyDown(container.firstElementChild, {key: 'Enter'});
});
});
2 changes: 1 addition & 1 deletion web/client/components/misc/style/gridcard.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
transition: box-shadow 250ms;
}

.gridcard:hover {
.gridcard:hover, .gridcard:focus {
box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23);
}

Expand Down
2 changes: 1 addition & 1 deletion web/client/themes/default/less/maps-properties.less
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@
.gridcard {
height: @square-btn-size * 4.5;
transition: all 0.3s;
&:hover {
&:hover, &:focus {
.shadow-far;
cursor: pointer;
z-index: 10;
Expand Down

0 comments on commit 608d54d

Please sign in to comment.