@ui5/webcomponents-react
Version:
React Wrapper for UI5 Web Components and additional components
29 lines • 881 B
JavaScript
import { useCallback } from 'react';
/**
* The `useAnnounceEmptyCells` plugin hook adds screen reader announcements for empty cells.
*
* **Note:** Some screen readers (depending on their configuration) automatically detect empty cells, potentially resulting in duplicate announcements of empty cells.
*/
export const useAnnounceEmptyCells = hooks => {
const setCellProps = useCallback((cellProps, {
cell: {
value
},
instance: {
webComponentsReactProperties: {
a11yElementIds: {
cellEmptyDescId
}
}
}
}) => {
if (typeof value !== 'number' && !value) {
return [cellProps, {
'aria-labelledby': `${cellProps['aria-labelledby']} ${cellEmptyDescId}`
}];
}
return cellProps;
}, []);
hooks.getCellProps.push(setCellProps);
};
useAnnounceEmptyCells.pluginName = 'useAnnounceEmptyCells';