@auth0/quantum-product 2.10.5 → 2.10.6

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.
@@ -58,7 +58,7 @@ var IconWrapper = styled('span')({
58
58
  });
59
59
  export var Segment = React.forwardRef(function (_a, ref) {
60
60
  var value = _a.value, label = _a.label, icon = _a.icon, _b = _a.disabled, disabled = _b === void 0 ? false : _b, analyticsId = _a.analyticsId, ariaLabel = _a["aria-label"], rest = __rest(_a, ["value", "label", "icon", "disabled", "analyticsId", 'aria-label']);
61
- var _c = useSegmentedControlContext(), selectedValue = _c.value, onChange = _c.onChange, _d = _c.size, size = _d === void 0 ? 'medium' : _d, _e = _c.fullWidth, fullWidth = _e === void 0 ? false : _e;
61
+ var _c = useSegmentedControlContext(), selectedValue = _c.value, tabFocusValue = _c.tabFocusValue, onChange = _c.onChange, _d = _c.size, size = _d === void 0 ? 'medium' : _d, _e = _c.fullWidth, fullWidth = _e === void 0 ? false : _e;
62
62
  var selected = selectedValue === value;
63
63
  var ownerState = {
64
64
  selected: selected,
@@ -71,7 +71,7 @@ export var Segment = React.forwardRef(function (_a, ref) {
71
71
  onChange(value);
72
72
  }
73
73
  };
74
- return (React.createElement(SegmentRoot, __assign({ ref: ref, type: "button", role: "radio", "aria-checked": selected, "aria-disabled": disabled, "aria-label": ariaLabel, disabled: disabled, tabIndex: !disabled && selected ? 0 : -1, onClick: handleClick, ownerState: ownerState }, (analyticsId && { 'data-analytics-id': analyticsId }), rest),
74
+ return (React.createElement(SegmentRoot, __assign({ ref: ref, type: "button", role: "radio", "aria-checked": selected, "aria-disabled": disabled, "aria-label": ariaLabel, "data-value": value }, (typeof value === 'number' && { 'data-numeric-value': '' }), { disabled: disabled, tabIndex: !disabled && value === tabFocusValue ? 0 : -1, onClick: handleClick, ownerState: ownerState }, (analyticsId && { 'data-analytics-id': analyticsId }), rest),
75
75
  icon && React.createElement(IconWrapper, { "aria-hidden": "true" }, icon),
76
76
  label));
77
77
  });
@@ -87,6 +87,19 @@ export var SegmentedControl = function (_a) {
87
87
  observer.observe(containerRef.current);
88
88
  return function () { return observer.disconnect(); };
89
89
  }, [updateIndicator]);
90
+ var _d = __read(React.useState(null), 2), focusedValue = _d[0], setFocusedValue = _d[1];
91
+ var tabFocusValue = React.useMemo(function () {
92
+ var _a, _b;
93
+ if (focusedValue != null)
94
+ return focusedValue;
95
+ var segments = React.Children.toArray(children).filter(function (child) {
96
+ return React.isValidElement(child);
97
+ });
98
+ var selected = segments.find(function (child) { return child.props.value === value; });
99
+ if (selected && !selected.props.disabled)
100
+ return value;
101
+ return (_b = (_a = segments.find(function (child) { return !child.props.disabled; })) === null || _a === void 0 ? void 0 : _a.props.value) !== null && _b !== void 0 ? _b : value;
102
+ }, [focusedValue, children, value]);
90
103
  var handleKeyDown = function (e) {
91
104
  if (!containerRef.current)
92
105
  return;
@@ -111,14 +124,32 @@ export var SegmentedControl = function (_a) {
111
124
  e.preventDefault();
112
125
  nextIndex = segments.length - 1;
113
126
  }
127
+ else if (e.key === 'Enter' || e.key === ' ') {
128
+ e.preventDefault();
129
+ var focused = document.activeElement;
130
+ if (focused && focused.dataset.value != null) {
131
+ var val = focused.dataset.numericValue != null ? Number(focused.dataset.value) : focused.dataset.value;
132
+ onChange === null || onChange === void 0 ? void 0 : onChange(val);
133
+ }
134
+ return;
135
+ }
114
136
  if (nextIndex !== null) {
115
- segments[nextIndex].focus();
116
- segments[nextIndex].click();
137
+ var nextEl = segments[nextIndex];
138
+ nextEl.focus();
139
+ var val = nextEl.dataset.numericValue != null ? Number(nextEl.dataset.value) : nextEl.dataset.value;
140
+ if (val != null)
141
+ setFocusedValue(val);
142
+ }
143
+ };
144
+ var handleBlur = function (e) {
145
+ var _a;
146
+ if (!((_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.relatedTarget))) {
147
+ setFocusedValue(null);
117
148
  }
118
149
  };
119
- var ctx = React.useMemo(function () { return ({ value: value, onChange: onChange, size: size, fullWidth: fullWidth }); }, [value, onChange, size, fullWidth]);
150
+ var ctx = React.useMemo(function () { return ({ value: value, tabFocusValue: tabFocusValue, onChange: onChange, size: size, fullWidth: fullWidth }); }, [value, tabFocusValue, onChange, size, fullWidth]);
120
151
  return (React.createElement(SegmentedControlContext.Provider, { value: ctx },
121
- React.createElement(Root, __assign({ ref: containerRef, fullWidth: fullWidth, role: "radiogroup", onKeyDown: handleKeyDown, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledby }, (analyticsId && { 'data-analytics-id': analyticsId }), rest),
152
+ React.createElement(Root, __assign({ ref: containerRef, fullWidth: fullWidth, role: "radiogroup", onKeyDown: handleKeyDown, onBlur: handleBlur, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledby }, (analyticsId && { 'data-analytics-id': analyticsId }), rest),
122
153
  React.createElement(Indicator, { "aria-hidden": "true", style: indicatorStyle }),
123
154
  children)));
124
155
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auth0/quantum-product",
3
- "version": "2.10.5",
3
+ "version": "2.10.6",
4
4
  "sideEffects": false,
5
5
  "license": "Apache-2.0",
6
6
  "publishConfig": {
@@ -94,7 +94,7 @@ var IconWrapper = (0, styled_1.styled)('span')({
94
94
  });
95
95
  exports.Segment = React.forwardRef(function (_a, ref) {
96
96
  var value = _a.value, label = _a.label, icon = _a.icon, _b = _a.disabled, disabled = _b === void 0 ? false : _b, analyticsId = _a.analyticsId, ariaLabel = _a["aria-label"], rest = __rest(_a, ["value", "label", "icon", "disabled", "analyticsId", 'aria-label']);
97
- var _c = (0, segmented_control_context_1.useSegmentedControlContext)(), selectedValue = _c.value, onChange = _c.onChange, _d = _c.size, size = _d === void 0 ? 'medium' : _d, _e = _c.fullWidth, fullWidth = _e === void 0 ? false : _e;
97
+ var _c = (0, segmented_control_context_1.useSegmentedControlContext)(), selectedValue = _c.value, tabFocusValue = _c.tabFocusValue, onChange = _c.onChange, _d = _c.size, size = _d === void 0 ? 'medium' : _d, _e = _c.fullWidth, fullWidth = _e === void 0 ? false : _e;
98
98
  var selected = selectedValue === value;
99
99
  var ownerState = {
100
100
  selected: selected,
@@ -107,7 +107,7 @@ exports.Segment = React.forwardRef(function (_a, ref) {
107
107
  onChange(value);
108
108
  }
109
109
  };
110
- return (React.createElement(SegmentRoot, __assign({ ref: ref, type: "button", role: "radio", "aria-checked": selected, "aria-disabled": disabled, "aria-label": ariaLabel, disabled: disabled, tabIndex: !disabled && selected ? 0 : -1, onClick: handleClick, ownerState: ownerState }, (analyticsId && { 'data-analytics-id': analyticsId }), rest),
110
+ return (React.createElement(SegmentRoot, __assign({ ref: ref, type: "button", role: "radio", "aria-checked": selected, "aria-disabled": disabled, "aria-label": ariaLabel, "data-value": value }, (typeof value === 'number' && { 'data-numeric-value': '' }), { disabled: disabled, tabIndex: !disabled && value === tabFocusValue ? 0 : -1, onClick: handleClick, ownerState: ownerState }, (analyticsId && { 'data-analytics-id': analyticsId }), rest),
111
111
  icon && React.createElement(IconWrapper, { "aria-hidden": "true" }, icon),
112
112
  label));
113
113
  });
@@ -1,6 +1,7 @@
1
1
  import * as React from 'react';
2
2
  export interface ISegmentedControlContextValue {
3
3
  value?: string | number;
4
+ tabFocusValue?: string | number;
4
5
  size?: 'small' | 'medium';
5
6
  fullWidth?: boolean;
6
7
  onChange?(value: string | number): void;
@@ -123,6 +123,19 @@ var SegmentedControl = function (_a) {
123
123
  observer.observe(containerRef.current);
124
124
  return function () { return observer.disconnect(); };
125
125
  }, [updateIndicator]);
126
+ var _d = __read(React.useState(null), 2), focusedValue = _d[0], setFocusedValue = _d[1];
127
+ var tabFocusValue = React.useMemo(function () {
128
+ var _a, _b;
129
+ if (focusedValue != null)
130
+ return focusedValue;
131
+ var segments = React.Children.toArray(children).filter(function (child) {
132
+ return React.isValidElement(child);
133
+ });
134
+ var selected = segments.find(function (child) { return child.props.value === value; });
135
+ if (selected && !selected.props.disabled)
136
+ return value;
137
+ return (_b = (_a = segments.find(function (child) { return !child.props.disabled; })) === null || _a === void 0 ? void 0 : _a.props.value) !== null && _b !== void 0 ? _b : value;
138
+ }, [focusedValue, children, value]);
126
139
  var handleKeyDown = function (e) {
127
140
  if (!containerRef.current)
128
141
  return;
@@ -147,14 +160,32 @@ var SegmentedControl = function (_a) {
147
160
  e.preventDefault();
148
161
  nextIndex = segments.length - 1;
149
162
  }
163
+ else if (e.key === 'Enter' || e.key === ' ') {
164
+ e.preventDefault();
165
+ var focused = document.activeElement;
166
+ if (focused && focused.dataset.value != null) {
167
+ var val = focused.dataset.numericValue != null ? Number(focused.dataset.value) : focused.dataset.value;
168
+ onChange === null || onChange === void 0 ? void 0 : onChange(val);
169
+ }
170
+ return;
171
+ }
150
172
  if (nextIndex !== null) {
151
- segments[nextIndex].focus();
152
- segments[nextIndex].click();
173
+ var nextEl = segments[nextIndex];
174
+ nextEl.focus();
175
+ var val = nextEl.dataset.numericValue != null ? Number(nextEl.dataset.value) : nextEl.dataset.value;
176
+ if (val != null)
177
+ setFocusedValue(val);
178
+ }
179
+ };
180
+ var handleBlur = function (e) {
181
+ var _a;
182
+ if (!((_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.relatedTarget))) {
183
+ setFocusedValue(null);
153
184
  }
154
185
  };
155
- var ctx = React.useMemo(function () { return ({ value: value, onChange: onChange, size: size, fullWidth: fullWidth }); }, [value, onChange, size, fullWidth]);
186
+ var ctx = React.useMemo(function () { return ({ value: value, tabFocusValue: tabFocusValue, onChange: onChange, size: size, fullWidth: fullWidth }); }, [value, tabFocusValue, onChange, size, fullWidth]);
156
187
  return (React.createElement(segmented_control_context_1.SegmentedControlContext.Provider, { value: ctx },
157
- React.createElement(Root, __assign({ ref: containerRef, fullWidth: fullWidth, role: "radiogroup", onKeyDown: handleKeyDown, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledby }, (analyticsId && { 'data-analytics-id': analyticsId }), rest),
188
+ React.createElement(Root, __assign({ ref: containerRef, fullWidth: fullWidth, role: "radiogroup", onKeyDown: handleKeyDown, onBlur: handleBlur, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledby }, (analyticsId && { 'data-analytics-id': analyticsId }), rest),
158
189
  React.createElement(Indicator, { "aria-hidden": "true", style: indicatorStyle }),
159
190
  children)));
160
191
  };