Skip to content

Commit 0607b4a

Browse files
committed
fix(Footer): add proper semantics
1 parent 15e7d60 commit 0607b4a

16 files changed

+33
-25
lines changed

.storybook/preview.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export const parameters = {
4646
['Base', ...Features],
4747
'Features',
4848
Features,
49+
'Mixing Features',
4950
'Theming',
5051
['Themes', 'CSS Class', 'Imperative Style'],
5152
'Library Themes',
@@ -57,7 +58,6 @@ export const parameters = {
5758
'Bootstrap (WIP)',
5859
'Ant Design (WIP)',
5960
],
60-
'Composites',
6161
['Sort & Select', 'Tree & Select', 'Tree & Sort'],
6262
'Types',
6363
['Data', 'Compact Table', 'Composed Table', ...Features, 'Virtualized'],

.storybook/stories/Composites/hide-horizontal.story.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { useTheme } from '@table-library/react-table-library/theme';
1515

1616
import { nodes } from '../data';
1717

18-
storiesOf('Composites/Column Hide & Horizontal', module)
18+
storiesOf('Mixing Features/Column Hide & Horizontal', module)
1919
.addParameters({ component: Table })
2020
.add('base', () => {
2121
const data = { nodes };

.storybook/stories/Composites/hide-resize.story.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414

1515
import { nodes } from '../data';
1616

17-
storiesOf('Composites/Column Hide & Resize', module)
17+
storiesOf('Mixing Features/Column Hide & Resize', module)
1818
.addParameters({ component: Table })
1919
.add('base', () => {
2020
const data = { nodes };

.storybook/stories/Composites/resize-fixed-column.story.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { useTheme } from '@table-library/react-table-library/theme';
1414

1515
import { nodes } from '../data';
1616

17-
storiesOf('Composites/Resize & Fixed Column', module)
17+
storiesOf('Mixing Features/Resize & Fixed Column', module)
1818
.addParameters({ component: Table })
1919
.add('base', () => {
2020
const data = { nodes };

.storybook/stories/Composites/resize-horizontal.story.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { useTheme } from '@table-library/react-table-library/theme';
1414

1515
import { nodes } from '../data';
1616

17-
storiesOf('Composites/Resize & Horizontal', module)
17+
storiesOf('Mixing Features/Resize & Horizontal', module)
1818
.addParameters({ component: Table })
1919
.add('base', () => {
2020
const data = { nodes };

.storybook/stories/Composites/sort-select.story.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121

2222
import { nodes } from '../data';
2323

24-
storiesOf('Composites/Sort & Select', module)
24+
storiesOf('Mixing Features/Sort & Select', module)
2525
.addParameters({ component: Table })
2626
.add('base', () => {
2727
const data = { nodes };

.storybook/stories/Composites/tree-select.story.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222

2323
import { nodes } from '../data';
2424

25-
storiesOf('Composites/Tree & Select', module)
25+
storiesOf('Mixing Features/Tree & Select', module)
2626
.addParameters({ component: Table })
2727
.add('base', () => {
2828
const data = { nodes };

.storybook/stories/Composites/tree-sort.story.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { useSort, HeaderCellSort } from '@table-library/react-table-library/sort
1616

1717
import { nodes } from '../data';
1818

19-
storiesOf('Composites/Tree & Sort', module)
19+
storiesOf('Mixing Features/Tree & Sort', module)
2020
.addParameters({ component: Table })
2121
.add('base', () => {
2222
const data = { nodes };

.storybook/stories/Types/theme.story.mdx

+2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import { Meta } from '@storybook/addon-docs';
88
export type Theme = {
99
Table?: string,
1010
Header?: string,
11+
Footer?: string,
1112
Body?: string,
1213
BaseRow?: string,
1314
HeaderRow?: string,
15+
FooterRow?: string,
1416
Row?: string,
1517
BaseCell?: string,
1618
HeaderCell?: string,

src/table/Cell/Cell.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const Cell: React.FC<CellProps> = ({
2929
if (colSpan) {
3030
colSpanStyle = {
3131
...colSpanStyle,
32-
'grid-column': `span ${colSpan} / ${index + colSpan + previousColSpans + 1}`,
32+
gridColumn: `span ${colSpan} / ${index + colSpan + previousColSpans + 1}`,
3333
};
3434
}
3535

src/table/Cell/HeaderCell.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export const HeaderCell: React.FC<HeaderCellProps> = ({
7575
pinLeft,
7676
pinRight,
7777
stiff,
78+
isFooter,
7879
colSpan = 0,
7980
previousColSpans = 0,
8081
resize,
@@ -93,7 +94,7 @@ export const HeaderCell: React.FC<HeaderCellProps> = ({
9394
if (colSpan) {
9495
colSpanStyle = {
9596
...colSpanStyle,
96-
'grid-column': `span ${colSpan} / ${index + colSpan + previousColSpans + 1}`,
97+
gridColumn: `span ${colSpan} / ${index + colSpan + previousColSpans + 1}`,
9798
};
9899
}
99100

@@ -109,7 +110,7 @@ export const HeaderCell: React.FC<HeaderCellProps> = ({
109110
style={{ ...colSpanStyle, ...style }}
110111
css={css`
111112
${theme?.BaseCell}
112-
${theme?.HeaderCell}
113+
${isFooter ? theme?.FooterCell : theme?.HeaderCell}
113114
`}
114115
className={cs('th', className, {
115116
stiff,

src/table/Footer/index.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import {
1010
HeaderCellProps,
1111
} from '@table-library/react-table-library/types/table';
1212

13-
const Footer: React.FC<HeaderProps> = (props) => <Header {...props} _className="tfoot" />;
13+
const Footer: React.FC<HeaderProps> = (props) => <Header {...props} isFooter />;
1414

1515
const FooterRow: React.FC<HeaderRowProps> = (props) => (
16-
<HeaderRow {...props} _className="tr-footer" role="rowfooter" />
16+
<HeaderRow {...props} isFooter role="rowfooter" />
1717
);
1818

1919
const FooterCell: React.FC<HeaderCellProps> = (props) => (
20-
<HeaderCell {...props} role="columnfooter" />
20+
<HeaderCell {...props} isFooter role="columnfooter" />
2121
);
2222

2323
export { Footer, FooterRow, FooterCell };

src/table/Header/index.tsx

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as React from 'react';
2+
import cs from 'clsx';
23
/** @jsxRuntime classic */
34
/** @jsx jsx */
45
import { css, jsx } from '@emotion/react';
@@ -12,11 +13,7 @@ const headerRow = `
1213
display: contents;
1314
`;
1415

15-
export const Header: React.FC<HeaderProps> = ({
16-
_className = 'thead',
17-
children,
18-
...rest
19-
}: HeaderProps) => {
16+
export const Header: React.FC<HeaderProps> = ({ isFooter, children, ...rest }: HeaderProps) => {
2017
const theme = React.useContext(ThemeContext);
2118

2219
const context = React.useContext(LayoutContext);
@@ -27,15 +24,15 @@ export const Header: React.FC<HeaderProps> = ({
2724

2825
const { layout } = context;
2926

30-
const As = layout?.isDiv ? 'div' : 'thead';
27+
const As = layout?.isDiv ? 'div' : isFooter ? 'tfoot' : 'thead';
3128

3229
return (
3330
<As
3431
role="rowgroup"
35-
className={_className}
32+
className={cs({ tfoot: isFooter, thead: !isFooter })}
3633
css={css`
3734
${headerRow}
38-
${theme?.Header}
35+
${isFooter ? theme?.Footer : theme?.Header}
3936
`}
4037
{...rest}
4138
>

src/table/Row/HeaderRow.tsx

+6-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const useInitialLayout = () => {
5757
export const HeaderRow: React.FC<HeaderRowProps> = ({
5858
className,
5959
role = 'rowheader',
60-
_className = 'tr-header',
60+
isFooter,
6161
children,
6262
...rest
6363
}: HeaderRowProps) => {
@@ -73,9 +73,12 @@ export const HeaderRow: React.FC<HeaderRowProps> = ({
7373
data-table-library_tr-header=""
7474
css={css`
7575
${theme?.BaseRow}
76-
${theme?.HeaderRow}
76+
${isFooter ? theme?.FooterRow : theme?.HeaderRow}
7777
`}
78-
className={cs('tr', _className, className)}
78+
className={cs('tr', className, {
79+
'tr-footer': isFooter,
80+
'tr-header': !isFooter,
81+
})}
7982
ref={ref}
8083
{...rest}
8184
>

src/types/table.ts

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export type HeaderCellProps = {
3333
pinLeft?: boolean;
3434
pinRight?: boolean;
3535
stiff?: boolean;
36+
isFooter?: boolean;
3637
resize?: ColumnResizeProps;
3738
children?: React.ReactNode;
3839
} & RestProps;
@@ -51,6 +52,7 @@ export type BodyProps = {
5152
} & RestProps;
5253

5354
export type HeaderRowProps = {
55+
isFooter?: boolean;
5456
className?: string;
5557
children: React.ReactNode;
5658
} & RestProps;

src/types/theme.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
export type Theme = {
22
Table?: string;
33
Header?: string;
4+
Footer?: string;
45
Body?: string;
56
BaseRow?: string;
67
HeaderRow?: string;
8+
FooterRow?: string;
79
Row?: string;
810
BaseCell?: string;
911
HeaderCell?: string;
12+
FooterCell?: string;
1013
Cell?: string;
1114
};

0 commit comments

Comments
 (0)