Skip to content

Commit 4025dfa

Browse files
committed
update srtext to be in state
1 parent e4bbb26 commit 4025dfa

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

packages/module/src/DataViewTh/DataViewTh.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,26 @@ export const DataViewTh: FC<DataViewThProps> = ({
5353
const thRef = useRef<HTMLTableCellElement>(null);
5454

5555
const [ width, setWidth ] = useState(resizableProps?.width ? resizableProps.width : 0);
56+
const [ screenreaderText, setScreenreaderText ] = useState(resizableProps?.screenreaderText || `Column ${width.toFixed(0)} pixels`);
57+
let currWidth = 0;
5658

5759
const isResizable = resizableProps?.isResizable || false;
5860
const increment = resizableProps?.increment || 5;
5961
const shiftIncrement = resizableProps?.shiftIncrement || 25;
6062
const resizeButtonAriaLabel = resizableProps?.resizeButtonAriaLabel || `Resize ${content}`;
6163
const onResize = resizableProps?.onResize || undefined;
62-
const screenreaderText = resizableProps?.screenreaderText || `Column ${width} pixels`;
6364

6465
const resizeButtonRef = useRef<HTMLButtonElement>(null);
6566
const setInitialVals = useRef(true);
6667
const dragOffset = useRef(0);
6768
const isResizing = useRef(false);
6869
const isInView = useRef(true);
69-
let currWidth = 0;
70+
71+
useEffect(() => {
72+
if (!resizableProps?.screenreaderText && currWidth > 0) {
73+
setScreenreaderText(`Column ${currWidth.toFixed(0)} pixels`);
74+
}
75+
}, [ currWidth ]);
7076

7177
useEffect(() => {
7278
if (!isResizable) {

0 commit comments

Comments
 (0)