Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix a11y #3

Open
wants to merge 6 commits into
base: modify_tree_view_with_table
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/react-docs/patternfly-a11y.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ async function waitFor(page) {
}

module.exports = {
prefix: 'http://localhost:5000',
prefix: 'http://localhost:8002',
waitFor,
crawl: false,
urls: Object.keys(fullscreenRoutes),
// urls: Object.keys(fullscreenRoutes),
urls: ['/components/table/react/tree-table', '/components/table/react/composable-tree-table'],
ignoreRules: 'color-contrast,page-has-heading-one,scrollable-region-focusable,bypass',
ignoreIncomplete: true,
skip: /^\/charts\//
Expand Down
5 changes: 3 additions & 2 deletions packages/react-table/src/components/Table/RowWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import { OUIAProps } from '@patternfly/react-core/dist/js/helpers/OUIA/ouia';
import { debounce } from '@patternfly/react-core/dist/js/helpers/util';
import { Tr } from '../TableComposable/Tr';
import { IRow } from './TableTypes';

// legacy export now, RowWrapperRow can simply be typed as IRow in the future
export interface RowWrapperRow {
Expand All @@ -15,7 +16,7 @@ export interface RowWrapperProps extends OUIAProps {
className?: string;
onScroll?: React.UIEventHandler;
onResize?: React.UIEventHandler;
row?: RowWrapperRow;
row?: IRow;
rowProps?: {
rowIndex: number;
rowKey: string;
Expand All @@ -31,7 +32,7 @@ export class RowWrapper extends React.Component<RowWrapperProps> {
isExpanded: undefined as boolean,
isHeightAuto: undefined as boolean,
isEditable: undefined as boolean
} as RowWrapperRow,
} as IRow,
rowProps: null as any
};
_unmounted: boolean;
Expand Down
10 changes: 6 additions & 4 deletions packages/react-table/src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
IHeaderRow,
OnFavorite
} from './TableTypes';
import { TreeRowWrapper } from './TreeRowWrapper';

export interface TableProps extends OUIAProps {
/** Adds an accessible name for the Table */
Expand Down Expand Up @@ -104,6 +105,8 @@ export interface TableProps extends OUIAProps {
onFavorite?: OnFavorite;
/** Along with the onSort prop, enables favorites sorting, defaults to true */
canSortFavorites?: boolean;
/** Flag indicating table is a tree table */
isTreeTable?: boolean;
}

export class Table extends React.Component<TableProps, {}> {
Expand All @@ -128,7 +131,8 @@ export class Table extends React.Component<TableProps, {}> {
selectVariant: 'checkbox',
ouiaSafe: true,
isStickyHeader: false,
canSortFavorites: true
canSortFavorites: true,
isTreeTable: false
};
state = {
ouiaStateId: getDefaultOUIAId(Table.displayName)
Expand Down Expand Up @@ -158,7 +162,6 @@ export class Table extends React.Component<TableProps, {}> {
'aria-label': ariaLabel,
caption,
header,
className,
onSort,
onSelect,
canSelectAll,
Expand Down Expand Up @@ -232,7 +235,7 @@ export class Table extends React.Component<TableProps, {}> {
renderers={{
body: {
wrapper: bodyWrapper || BodyWrapper,
row: rowWrapper || RowWrapper,
row: rowWrapper || (this.props.isTreeTable ? TreeRowWrapper : RowWrapper),
cell: BodyCell
},
header: {
Expand All @@ -243,7 +246,6 @@ export class Table extends React.Component<TableProps, {}> {
role={role}
variant={variant}
borders={borders}
className={className}
>
{caption && <caption>{caption}</caption>}
{children}
Expand Down
14 changes: 14 additions & 0 deletions packages/react-table/src/components/Table/TableTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
DropdownDirection,
DropdownPosition
} from '@patternfly/react-core/dist/js/components/Dropdown/dropdownConstants';
import * as React from 'react';

export enum TableGridBreakpoint {
none = '',
Expand Down Expand Up @@ -67,6 +68,19 @@ export type OnFavorite = (
rowData: IRowData,
extraData: IExtraData
) => void;
export type OnTreeRowCollapse = (
event: any,
rowIndex: number,
title: string | React.ReactNode,
rowData: IRowData
) => void;
export type OnCheckChange = (
event: React.FormEvent<HTMLInputElement>,
isChecked: boolean,
rowIndex: number,
title: string | React.ReactNode,
rowData: IRowData
) => void;

// Todo: Update type with next breaking change release
// export type IHeaderRow = ColumnType;
Expand Down
27 changes: 27 additions & 0 deletions packages/react-table/src/components/Table/TreeRowWrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as React from 'react';
import { css } from '@patternfly/react-styles';
import styles from '@patternfly/react-styles/css/components/Table/table';
import { RowWrapperProps } from './RowWrapper';
import { Tr } from '../TableComposable';

export const TreeRowWrapper: React.FunctionComponent<RowWrapperProps> = ({
className,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
rowProps,
...props
}: RowWrapperProps) => {
const { level, posinset, setsize, isExpanded, isHidden } = props.row.props;
return (
<Tr
role="treeitem"
aria-level={level}
aria-posinset={posinset}
aria-setsize={setsize}
aria-expanded={!!isExpanded}
isHidden={isHidden}
className={css(className, isExpanded && 'pf-m-expandable', isExpanded && styles.modifiers.expanded)}
{...props}
/>
);
};
TreeRowWrapper.displayName = 'TreeRowWrapper';
Loading