Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit 8921292

Browse files
committed
feat(plugins/plugin-client-common): improve accessibility of "red" error grid cells
Fixes #4938
1 parent f88ef97 commit 8921292

File tree

3 files changed

+58
-20
lines changed

3 files changed

+58
-20
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2020 IBM Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import * as React from 'react'
18+
19+
export default function ErrorCell() {
20+
return (
21+
<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 24 24">
22+
<g fill="none" fillRule="evenodd" stroke="none" strokeWidth="1">
23+
<path fill="var(--color-base0E)" d="M0 0H24V24H0z"></path>
24+
<path
25+
fill="var(--color-base07)"
26+
d="M15.0914286 16L12 12.9085714 8.90857143 16 8 15.0914286 11.0914286 12 8 8.90857143 8.90857143 8 12 11.0914286 15.0914286 8 16 8.90857143 12.9085714 12 16 15.0914286z"
27+
></path>
28+
</g>
29+
</svg>
30+
)
31+
}

plugins/plugin-client-common/src/components/Content/Table/Grid.tsx

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { Tab, REPL, Table as KuiTable } from '@kui-shell/core'
1818

1919
import * as React from 'react'
2020

21+
import ErrorCell from './ErrorCell'
2122
import { onClickForCell } from './TableCell'
2223
import { NamedDataTableRow } from './kui2carbon'
2324

@@ -52,28 +53,29 @@ export default class Grid<P extends Props> extends React.PureComponent<P> {
5253
<div className="bx--data-table kui--data-table-as-grid" style={style}>
5354
{response.body.map((kuiRow, kidx) => {
5455
const badgeCell = gridableColumn !== -1 && kuiRow.attributes[gridableColumn]
55-
const title = `${kuiRow.name}: ${badgeCell ? badgeCell.value : ''}`
56+
const title = `${kuiRow.name}\n${badgeCell ? badgeCell.value : ''}`
5657
const css = badgeCell ? badgeCell.css : 'kui--status-unknown'
5758

5859
// cell label, to be displayed inside of the grid cell
5960
const label = <span className="kui--grid-cell-label">{kuiRow.name.slice(0, 2)}</span>
6061

62+
const props = {
63+
title,
64+
key: kuiRow.attributes[gridableColumn].css, // force restart of animation if color changes
65+
'data-tag': 'badge-circle',
66+
'data-just-updated': this.props.justUpdated[kuiRow.rowKey || kuiRow.name],
67+
className: css,
68+
onClick: onClickForCell(
69+
kuiRow,
70+
tab,
71+
repl,
72+
kuiRow.attributes.find(_ => _.onclick)
73+
)
74+
}
75+
6176
return (
6277
<span key={kidx} data-tag="badge" data-entity-name={kuiRow.name}>
63-
<span
64-
title={title}
65-
data-tag="badge-circle"
66-
data-just-updated={this.props.justUpdated[kuiRow.rowKey || kuiRow.name]}
67-
className={css}
68-
onClick={onClickForCell(
69-
kuiRow,
70-
tab,
71-
repl,
72-
kuiRow.attributes.find(_ => _.onclick)
73-
)}
74-
>
75-
{label}
76-
</span>
78+
<span {...props}>{/red-background/.test(css) ? <ErrorCell /> : label}</span>
7779
</span>
7880
)
7981
})}

plugins/plugin-client-common/src/components/Content/Table/TableCell.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { Cell as KuiCell, Row as KuiRow, Tab, REPL } from '@kui-shell/core'
18-
1917
import * as React from 'react'
2018
import { TableCell, DataTableCell } from 'carbon-components-react'
19+
import { Cell as KuiCell, Row as KuiRow, Tab, REPL } from '@kui-shell/core'
20+
21+
import ErrorCell from './ErrorCell'
2122

2223
/**
2324
* Generate an onclick handler for a cell
@@ -79,6 +80,8 @@ export default function renderCell(kuiRow: KuiRow, justUpdated: boolean, tab: Ta
7980
? (kuiRow.css || '') + (kuiRow.onclick ? ' clickable' : '')
8081
: (kuiRow.attributes[cidx - 1].css || '') + (kuiRow.attributes[cidx - 1].onclick ? ' clickable' : ''))
8182

83+
const css = cidx > 0 ? kuiRow.attributes[cidx - 1].css : undefined
84+
8285
// the text value of the cell
8386
const innerText = (kuiRow.attributes[cidx - 1] && kuiRow.attributes[cidx - 1].valueDom) || cell.value
8487

@@ -96,12 +99,14 @@ export default function renderCell(kuiRow: KuiRow, justUpdated: boolean, tab: Ta
9699
>
97100
{tag === 'badge' && (
98101
<span
99-
key={kuiRow.attributes[cidx - 1].css /* force restart of animation if color changes */}
102+
key={css /* force restart of animation if color changes */}
100103
title={innerText}
104+
className={css || 'kui--status-unknown'}
101105
data-tag="badge-circle"
102-
className={kuiRow.attributes[cidx - 1].css}
103106
data-just-updated={justUpdated || undefined}
104-
/>
107+
>
108+
{/red-background/.test(css) ? <ErrorCell /> : undefined}
109+
</span>
105110
)}
106111
<span className="kui--cell-inner-text">{innerText}</span>
107112
</span>

0 commit comments

Comments
 (0)