@deque/cauldron-react 4.2.1-canary.f766f9dd → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,9 +6,11 @@ interface TableHeaderProps extends ThHTMLAttributes<HTMLTableCellElement> {
6
6
  sortDirection?: SortDirection;
7
7
  onSort?: () => void;
8
8
  className?: string;
9
+ sortAscendingAnnouncement?: string;
10
+ sortDescendingAnnouncemen?: string;
9
11
  }
10
12
  declare const TableHeader: {
11
- ({ children, sortDirection, onSort, className, ...other }: TableHeaderProps): JSX.Element;
13
+ ({ children, sortDirection, onSort, className, sortAscendingAnnouncement, sortDescendingAnnouncemen, ...other }: TableHeaderProps): JSX.Element;
12
14
  displayName: string;
13
15
  propTypes: {
14
16
  children: PropTypes.Validator<string | number | boolean | {} | PropTypes.ReactElementLike | PropTypes.ReactNodeArray>;
package/lib/index.js CHANGED
@@ -8000,9 +8000,31 @@ function AxeLoader() {
8000
8000
  React__default.createElement("path", { fill: "currentColor", d: "M379 549.9h-27.6v-16.7c-7.4 13.5-22.8 20.2-39 20.2-37.1 0-58.9-28.9-58.9-61.6 0-36.5 26.4-61.4 58.9-61.4 21.1 0 34 11.2 39 20.5V434H379v115.9zm-97.8-57.4c0 14.3 10.3 35.2 35.2 35.2 15.4 0 25.5-8 30.8-18.6 2.7-5.1 4-10.5 4.4-16.2.2-5.5-.8-11.2-3.2-16.2-4.9-11-15.6-20.5-32.3-20.5-22.4 0-35 18.1-35 36.1v.2zM436.2 488.9l-39-54.8h33.3l22.6 35.6 22.6-35.6h32.9l-38.8 54.8 43.2 61h-34L453.1 510l-26.2 39.9h-33.5l42.8-61z" })));
8001
8001
  }
8002
8002
 
8003
- var LoaderOverlay = React__default.forwardRef(function (_a, ref) {
8003
+ /**
8004
+ * When a component needs to track an internal ref on a component that has a
8005
+ * forwarded ref, useSharedRef will return a MutableRefObject<T> that will
8006
+ * correctly invoke the parent ref as well providing an internal ref.
8007
+ *
8008
+ * @example
8009
+ * React.forwardRef(function Component({ children }, ref) {
8010
+ * const internalRef = useSharedRef<HTMLElement>(ref)
8011
+ * if (internalRef.current) {
8012
+ * // do something with the internal ref...
8013
+ * }
8014
+ * return (<div ref={internalRef}>...</div>)
8015
+ * })
8016
+ */
8017
+ function useSharedRef(ref) {
8018
+ var internalRef = React.useRef();
8019
+ React.useEffect(function () {
8020
+ setRef(ref, internalRef.current);
8021
+ }, [ref]);
8022
+ return internalRef;
8023
+ }
8024
+
8025
+ var LoaderOverlay = React.forwardRef(function (_a, ref) {
8004
8026
  var className = _a.className, variant = _a.variant, label = _a.label, children = _a.children, focusOnInitialRender = _a.focusOnInitialRender, other = tslib.__rest(_a, ["className", "variant", "label", "children", "focusOnInitialRender"]);
8005
- var overlayRef = typeof ref === 'function' || !ref ? React.createRef() : ref;
8027
+ var overlayRef = useSharedRef(ref);
8006
8028
  React.useEffect(function () {
8007
8029
  if (!!focusOnInitialRender && overlayRef.current) {
8008
8030
  setTimeout(function () {
@@ -8012,11 +8034,6 @@ var LoaderOverlay = React__default.forwardRef(function (_a, ref) {
8012
8034
  }
8013
8035
  return;
8014
8036
  }, [overlayRef.current]);
8015
- React.useEffect(function () {
8016
- if (typeof ref === 'function') {
8017
- ref(overlayRef.current);
8018
- }
8019
- }, [ref]);
8020
8037
  return (React__default.createElement("div", tslib.__assign({ className: classNames('Loader__overlay', className, variant === 'large'
8021
8038
  ? 'Loader__overlay--large'
8022
8039
  : variant === 'small'
@@ -8106,13 +8123,26 @@ TableHead.propTypes = {
8106
8123
  };
8107
8124
 
8108
8125
  var TableHeader = function (_a) {
8109
- var children = _a.children, sortDirection = _a.sortDirection, onSort = _a.onSort, className = _a.className, other = tslib.__rest(_a, ["children", "sortDirection", "onSort", "className"]);
8126
+ var children = _a.children, sortDirection = _a.sortDirection, onSort = _a.onSort, className = _a.className, _b = _a.sortAscendingAnnouncement, sortAscendingAnnouncement = _b === void 0 ? 'sorted ascending' : _b, _c = _a.sortDescendingAnnouncemen, sortDescendingAnnouncemen = _c === void 0 ? 'sorted descending' : _c, other = tslib.__rest(_a, ["children", "sortDirection", "onSort", "className", "sortAscendingAnnouncement", "sortDescendingAnnouncemen"]);
8127
+ // When the sort direction changes, we want to announce the change in a live region
8128
+ // because changes to the sort value is not widely supported yet
8129
+ // see: https://a11ysupport.io/tech/aria/aria-sort_attribute
8130
+ var _d = tslib.__read(React.useState(''), 2), announcement = _d[0], setAnnouncement = _d[1];
8131
+ React.useEffect(function () {
8132
+ if (sortDirection !== 'none') {
8133
+ setAnnouncement(sortDirection === 'ascending'
8134
+ ? sortAscendingAnnouncement
8135
+ : sortDescendingAnnouncemen);
8136
+ }
8137
+ }, [sortDirection]);
8110
8138
  return (React__default.createElement("th", tslib.__assign({ "aria-sort": sortDirection, className: classNames('TableHeader', className, {
8111
8139
  'TableHeader--sort-ascending': sortDirection === 'ascending',
8112
8140
  'TableHeader--sort-descending': sortDirection === 'descending'
8113
8141
  }) }, other), !!onSort && !!sortDirection ? (React__default.createElement("button", { onClick: onSort, className: "TableHeader__sort-button", type: "button" },
8114
8142
  children,
8115
- React__default.createElement("span", { "aria-hidden": "true" }, sortDirection === 'none' ? (React__default.createElement(Icon, { type: "sort-triangle" })) : sortDirection === 'ascending' ? (React__default.createElement(Icon, { type: "triangle-up" })) : (React__default.createElement(Icon, { type: "triangle-down" }))))) : (children)));
8143
+ React__default.createElement("span", { "aria-hidden": "true" }, sortDirection === 'none' ? (React__default.createElement(Icon, { type: "sort-triangle" })) : sortDirection === 'ascending' ? (React__default.createElement(Icon, { type: "triangle-up" })) : (React__default.createElement(Icon, { type: "triangle-down" }))),
8144
+ React__default.createElement(Offscreen, null,
8145
+ React__default.createElement("span", { role: "status", "aria-live": "polite" }, announcement)))) : (children)));
8116
8146
  };
8117
8147
  TableHeader.displayName = 'TableHeader';
8118
8148
  TableHeader.propTypes = {
@@ -0,0 +1,16 @@
1
+ import { MutableRefObject, Ref } from 'react';
2
+ /**
3
+ * When a component needs to track an internal ref on a component that has a
4
+ * forwarded ref, useSharedRef will return a MutableRefObject<T> that will
5
+ * correctly invoke the parent ref as well providing an internal ref.
6
+ *
7
+ * @example
8
+ * React.forwardRef(function Component({ children }, ref) {
9
+ * const internalRef = useSharedRef<HTMLElement>(ref)
10
+ * if (internalRef.current) {
11
+ * // do something with the internal ref...
12
+ * }
13
+ * return (<div ref={internalRef}>...</div>)
14
+ * })
15
+ */
16
+ export default function useSharedRef<T>(ref: Ref<T>): MutableRefObject<T>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deque/cauldron-react",
3
- "version": "4.2.1-canary.f766f9dd",
3
+ "version": "4.3.0",
4
4
  "description": "Fully accessible react components library for Deque Cauldron",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -124,4 +124,4 @@
124
124
  "\\.svg$": "<rootDir>/__tests__/svgMock.js"
125
125
  }
126
126
  }
127
- }
127
+ }