@fluentui/react-northstar
Version:
A themable React component library.
132 lines (131 loc) • 5.87 kB
JavaScript
import _invoke from "lodash/invoke";
import _map from "lodash/map";
import { tableBehavior } from '@fluentui/accessibility';
import { getElementType, useTelemetry, mergeVariablesOverrides, useUnhandledProps, useAccessibility, useStyles, useFluentContext } from '@fluentui/react-bindings';
import * as customPropTypes from '@fluentui/react-proptypes';
import * as PropTypes from 'prop-types';
import * as React from 'react';
import { commonPropTypes, childrenExist, createShorthandFactory } from '../../utils';
import { TableRow } from './TableRow';
import { TableCell } from './TableCell';
export var tableClassName = 'ui-table';
export var tableSlotClassNames = {
header: tableClassName + "__header"
};
/**
* A Table is used to display data in tabular layout
* * @accessibility
* Implements ARIA [Data Grid](https://www.w3.org/TR/wai-aria-practices/#dataGrid) design pattern for presenting tabular information.
* When gridcell contains actionable element, use [gridCellWithFocusableElementBehavior](/components/table/accessibility#grid-cell-with-focusable-element-behavior-ts). [More information available in aria documentation.](https://www.w3.org/TR/wai-aria-practices/#gridNav_focus)
* Use [gridCellMultipleFocusableBehavior](/components/table/accessibility#gridCellMultipleFocusableBehavior), when gridcell contains:
* \- editable content
* \- multiple actionable elements
* \- component that utilizes arrow keys in its navigation, like menu button, dropdown, radio group, slider, etc.
* [More information available in aria documentation.](https://www.w3.org/TR/wai-aria-practices/#gridNav_inside)
* @accessibilityIssues
* [NVDA narrate table title(aria-label) twice](https://github.com/nvaccess/nvda/issues/10548)
* [Accessibility DOM > Table > gridcell > when gridcell is focused, then selected state is send to reader](https://bugs.chromium.org/p/chromium/issues/detail?id=1030378)
* [JAWS narrate grid name twice, once as table and second time as grid](https://github.com/FreedomScientific/VFO-standards-support/issues/346)
* [JAWS doesn't narrate grid column name, when focus is on actionable element in the cell] (https://github.com/FreedomScientific/VFO-standards-support/issues/348)
* [aria-sort is not output at child elements](https://github.com/FreedomScientific/VFO-standards-support/issues/319)
* [VoiceOver not announcing rows correctly for a grid with presentation elements inside](https://bugs.chromium.org/p/chromium/issues/detail?id=1054424)
* VoiceOver doesn't narrate aria-rowcount value in table or grid
*/
export var Table = /*#__PURE__*/function () {
var Table = /*#__PURE__*/React.forwardRef(function (props, ref) {
var context = useFluentContext();
var _useTelemetry = useTelemetry(Table.displayName, context.telemetry),
setStart = _useTelemetry.setStart,
setEnd = _useTelemetry.setEnd;
setStart();
var children = props.children,
rows = props.rows,
header = props.header,
compact = props.compact,
accessibility = props.accessibility,
className = props.className,
design = props.design,
styles = props.styles,
variables = props.variables;
var hasChildren = childrenExist(children);
var ElementType = getElementType(props);
var unhandledProps = useUnhandledProps(Table.handledProps, props);
var getA11yProps = useAccessibility(accessibility, {
debugName: Table.displayName,
rtl: context.rtl
});
var _useStyles = useStyles(Table.displayName, {
className: tableClassName,
mapPropsToInlineStyles: function mapPropsToInlineStyles() {
return {
className: className,
design: design,
styles: styles,
variables: variables
};
},
rtl: context.rtl
}),
classes = _useStyles.classes;
var renderRows = function renderRows() {
return _map(rows, function (row) {
return TableRow.create(row, {
defaultProps: function defaultProps() {
return getA11yProps('row', {
compact: compact,
onClick: function onClick(e, props) {
_invoke(row, 'onClick', e, props);
}
});
},
overrideProps: function overrideProps(predefinedProps) {
return {
variables: mergeVariablesOverrides(variables, predefinedProps.variables)
};
}
});
});
};
var renderHeader = function renderHeader() {
return TableRow.create(header, {
defaultProps: function defaultProps() {
return getA11yProps('row', {
header: true,
compact: compact,
className: tableSlotClassNames.header
});
},
overrideProps: function overrideProps(predefinedProps) {
return {
variables: mergeVariablesOverrides(variables, predefinedProps.variables)
};
}
});
};
var element = getA11yProps.unstable_wrapWithFocusZone( /*#__PURE__*/React.createElement(ElementType, getA11yProps('root', Object.assign({
className: classes.root,
ref: ref
}, unhandledProps)), hasChildren && children, !hasChildren && renderHeader(), !hasChildren && renderRows()));
setEnd();
return element;
});
Table.displayName = 'Table';
Table.Cell = TableCell;
Table.Row = TableRow;
Table.create = createShorthandFactory({
Component: Table
});
Table.propTypes = Object.assign({}, commonPropTypes.createCommon({
content: false
}), {
header: customPropTypes.itemShorthand,
rows: customPropTypes.collectionShorthand,
compact: PropTypes.bool
});
Table.handledProps = Object.keys(Table.propTypes);
Table.defaultProps = {
accessibility: tableBehavior
};
return Table;
}();
//# sourceMappingURL=Table.js.map