Skip to content

Commit 5a7b0e0

Browse files
committed
updated example to properly update srtext
1 parent 37674b8 commit 5a7b0e0

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

packages/module/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableResizableColumnsExample.tsx

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -103,31 +103,32 @@ const rows: DataViewTr[] = repositories.map(({ id, name, branches, prs, workspac
103103
{ cell: <ActionsColumn items={rowActions} />, props: { isActionCell: true } }
104104
]);
105105

106-
const columns: DataViewTh[] = [
107-
null,
108-
'Repositories',
109-
{
110-
cell: 'col',
111-
resizableProps: { isResizable: true }
112-
},
113-
'Pull requests',
114-
{ cell: 'Workspaces', props: { info: { tooltip: 'More information' } } },
115-
{ cell: 'Last commit', props: { sort: { sortBy: {}, columnIndex: 4 } } }
116-
];
117-
118106
const ouiaId = 'TableExample';
119107

120108
export const ResizableColumnsExample: FunctionComponent = () => {
121109
const [ screenReaderText, setScreenReaderText ] = useState('');
122110

123-
if (columns[2] && isDataViewThObject(columns[2]) && columns[2].resizableProps) {
124-
columns[2].resizableProps.onResize = (_e, width) => {
125-
// eslint-disable-next-line no-console
126-
console.log('resized width: ', width);
127-
setScreenReaderText(`Column ${width} pixels`);
128-
};
129-
columns[2].resizableProps.screenreaderText = screenReaderText;
130-
}
111+
const onResize = (_e, width) => {
112+
// eslint-disable-next-line no-console
113+
console.log('resized width: ', width);
114+
setScreenReaderText(`Column ${width} pixels`);
115+
};
116+
117+
const columns: DataViewTh[] = [
118+
null,
119+
'Repositories',
120+
{
121+
cell: 'col',
122+
resizableProps: {
123+
isResizable: true,
124+
onResize,
125+
screenreaderText: screenReaderText
126+
}
127+
},
128+
'Pull requests',
129+
{ cell: 'Workspaces', props: { info: { tooltip: 'More information' } } },
130+
{ cell: 'Last commit', props: { sort: { sortBy: {}, columnIndex: 4 } } }
131+
];
131132

132133
return <DataViewTable isResizable aria-label="Repositories table" ouiaId={ouiaId} columns={columns} rows={rows} />;
133134
};

packages/module/src/DataViewTh/DataViewTh.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export const DataViewTh: FC<DataViewThProps> = ({
6060
const resizeButtonAriaLabel = resizableProps?.resizeButtonAriaLabel || `Resize ${content}`;
6161
const onResize = resizableProps?.onResize || undefined;
6262
const screenreaderText = resizableProps?.screenreaderText || `Column ${width} pixels`;
63+
console.log('sr text', resizableProps?.screenreaderText);
6364

6465
const resizeButtonRef = useRef<HTMLButtonElement>(null);
6566
const setInitialVals = useRef(true);

0 commit comments

Comments
 (0)