@oslokommune/punkt-react 20.3.1 → 20.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/components/table/TableHeaderCell.d.ts +2 -2
- package/dist/components/table/TableHeaderCell.js +1 -1
- package/dist/punkt-react.cjs +1 -1
- package/package.json +3 -3
- package/src/components/table/Table.test.tsx +64 -0
- package/src/components/table/TableHeaderCell.tsx +7 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslokommune/punkt-react",
|
|
3
|
-
"version": "20.
|
|
3
|
+
"version": "20.4.0",
|
|
4
4
|
"description": "React komponentbibliotek til Punkt, designsystem for Oslo kommune",
|
|
5
5
|
"homepage": "https://punkt.oslo.kommune.no",
|
|
6
6
|
"author": "Team Designsystem, Oslo kommune",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@eslint/eslintrc": "^3.3.5",
|
|
43
43
|
"@eslint/js": "^10.0.1",
|
|
44
44
|
"@oslokommune/punkt-assets": "^20.0.5",
|
|
45
|
-
"@oslokommune/punkt-css": "^20.
|
|
45
|
+
"@oslokommune/punkt-css": "^20.4.0",
|
|
46
46
|
"@testing-library/jest-dom": "^7.0.1",
|
|
47
47
|
"@testing-library/react": "^16.3.3",
|
|
48
48
|
"@testing-library/user-event": "^14.6.8",
|
|
@@ -102,5 +102,5 @@
|
|
|
102
102
|
"url": "https://github.com/oslokommune/punkt/issues"
|
|
103
103
|
},
|
|
104
104
|
"license": "MIT",
|
|
105
|
-
"gitHead": "
|
|
105
|
+
"gitHead": "760f1090183d6175bede02090853df2f6ffc9917"
|
|
106
106
|
}
|
|
@@ -64,6 +64,70 @@ describe('<PktTable />', () => {
|
|
|
64
64
|
expect(screen.getByTestId('pkt-table')).not.toHaveClass('pkt-table--zebra-blue')
|
|
65
65
|
})
|
|
66
66
|
|
|
67
|
+
describe('header cell role', () => {
|
|
68
|
+
const table = (scope?: 'col' | 'row' | 'rowgroup') =>
|
|
69
|
+
render(
|
|
70
|
+
<PktTable>
|
|
71
|
+
<PktTableBody>
|
|
72
|
+
<PktTableRow>
|
|
73
|
+
<PktTableHeaderCell scope={scope}>Water</PktTableHeaderCell>
|
|
74
|
+
<PktTableDataCell dataLabel="Price">10</PktTableDataCell>
|
|
75
|
+
</PktTableRow>
|
|
76
|
+
</PktTableBody>
|
|
77
|
+
</PktTable>,
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
test('is columnheader by default', () => {
|
|
81
|
+
table()
|
|
82
|
+
expect(screen.getByText('Water')).toHaveAttribute('role', 'columnheader')
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
test('is columnheader with scope col', () => {
|
|
86
|
+
table('col')
|
|
87
|
+
expect(screen.getByText('Water')).toHaveAttribute('role', 'columnheader')
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
test.each(['row', 'rowgroup'] as const)('is rowheader with scope %s', (scope) => {
|
|
91
|
+
table(scope)
|
|
92
|
+
expect(screen.getByRole('rowheader', { name: 'Water' })).toHaveAttribute('scope', scope)
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
test('lets an explicit role win', () => {
|
|
96
|
+
render(
|
|
97
|
+
<PktTable>
|
|
98
|
+
<PktTableBody>
|
|
99
|
+
<PktTableRow>
|
|
100
|
+
<PktTableHeaderCell scope="row" role="columnheader">
|
|
101
|
+
Water
|
|
102
|
+
</PktTableHeaderCell>
|
|
103
|
+
</PktTableRow>
|
|
104
|
+
</PktTableBody>
|
|
105
|
+
</PktTable>,
|
|
106
|
+
)
|
|
107
|
+
expect(screen.getByText('Water')).toHaveAttribute('role', 'columnheader')
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
test('has no accessibility violations with row headers', async () => {
|
|
111
|
+
const { container } = render(
|
|
112
|
+
<PktTable>
|
|
113
|
+
<PktTableHeader>
|
|
114
|
+
<PktTableRow>
|
|
115
|
+
<PktTableHeaderCell scope="col">Item</PktTableHeaderCell>
|
|
116
|
+
<PktTableHeaderCell scope="col">Price</PktTableHeaderCell>
|
|
117
|
+
</PktTableRow>
|
|
118
|
+
</PktTableHeader>
|
|
119
|
+
<PktTableBody>
|
|
120
|
+
<PktTableRow>
|
|
121
|
+
<PktTableHeaderCell scope="row">Water</PktTableHeaderCell>
|
|
122
|
+
<PktTableDataCell dataLabel="Price">10</PktTableDataCell>
|
|
123
|
+
</PktTableRow>
|
|
124
|
+
</PktTableBody>
|
|
125
|
+
</PktTable>,
|
|
126
|
+
)
|
|
127
|
+
expect(await axe(container)).toHaveNoViolations()
|
|
128
|
+
})
|
|
129
|
+
})
|
|
130
|
+
|
|
67
131
|
describe('deprecated skin "zebra-blue"', () => {
|
|
68
132
|
afterEach(() => vi.restoreAllMocks())
|
|
69
133
|
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import classNames from 'classnames'
|
|
2
|
-
import type {
|
|
2
|
+
import type { ReactNode, ThHTMLAttributes } from 'react'
|
|
3
3
|
|
|
4
|
-
interface ITableHeaderCellProps extends
|
|
4
|
+
interface ITableHeaderCellProps extends ThHTMLAttributes<HTMLTableCellElement> {
|
|
5
5
|
className?: string
|
|
6
6
|
children: ReactNode
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export const PktTableHeaderCell = ({ className, children, ...props }: ITableHeaderCellProps) => (
|
|
10
|
-
<th
|
|
10
|
+
<th
|
|
11
|
+
className={classNames(className, 'pkt-table__header-cell', {})}
|
|
12
|
+
role={props.scope === 'row' || props.scope === 'rowgroup' ? 'rowheader' : 'columnheader'}
|
|
13
|
+
{...props}
|
|
14
|
+
>
|
|
11
15
|
{children}
|
|
12
16
|
</th>
|
|
13
17
|
)
|