@pingux/astro 2.93.0-alpha.3 → 2.93.0-alpha.4

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.
@@ -40,8 +40,9 @@ var IndeterminateCheckboxIcon = function IndeterminateCheckboxIcon(props) {
40
40
  viewBox: "0 0 24 24",
41
41
  fill: "none",
42
42
  xmlns: "http://www.w3.org/2000/svg",
43
- "aria-labelledby": "checkbox-icon-title"
44
- }, (0, _lodash.omit)(props, 'id', 'aria-checked')), (0, _react2.jsx)("title", {
43
+ "aria-labelledby": "checkbox-icon-title",
44
+ "data-testid": "checkbox-icon-indeterminate"
45
+ }, (0, _lodash.omit)(props, 'id', 'aria-checked', 'data-testid')), (0, _react2.jsx)("title", {
45
46
  id: "checkbox-icon-title"
46
47
  }, "Indeterminate Checkbox Icon"), (0, _react2.jsx)("rect", {
47
48
  x: "3.5",
@@ -34,6 +34,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
34
34
  var displayName = 'CheckboxField';
35
35
  var CheckboxField = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
36
36
  var label = props.label,
37
+ checkBoxProps = props.checkBoxProps,
37
38
  _props$controlProps = props.controlProps,
38
39
  controlProps = _props$controlProps === void 0 ? {} : _props$controlProps,
39
40
  hasAutoFocus = props.hasAutoFocus,
@@ -84,7 +85,7 @@ var CheckboxField = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
84
85
  }, fieldLabelProps), (0, _react2.jsx)(_.Checkbox, (0, _extends2["default"])({
85
86
  ref: checkboxRef,
86
87
  "aria-describedby": helperText && helperTextId
87
- }, fieldControlInputProps)), label)), helperText && (0, _react2.jsx)(_.FieldHelperText, {
88
+ }, (0, _reactAria.mergeProps)(fieldControlInputProps, checkBoxProps))), label)), helperText && (0, _react2.jsx)(_.FieldHelperText, {
88
89
  status: status,
89
90
  sx: {
90
91
  pt: 7
@@ -57,6 +57,24 @@ test('checkbox interaction', function () {
57
57
  expect(input).not.toBeChecked();
58
58
  expect(onChange).toHaveBeenNthCalledWith(2, false);
59
59
  });
60
+ test('checkbox interaction on svg', function () {
61
+ var onChange = jest.fn();
62
+ getComponent({
63
+ onChange: onChange,
64
+ checkBoxProps: {
65
+ 'data-testid': 'checkbox-icon'
66
+ }
67
+ });
68
+ var input = _testWrapper.screen.getByRole('checkbox');
69
+ var svg = _testWrapper.screen.getByTestId('checkbox-icon');
70
+ expect(onChange).not.toHaveBeenCalled();
71
+ _userEvent["default"].click(svg);
72
+ expect(input).toBeChecked();
73
+ expect(onChange).toHaveBeenNthCalledWith(1, true);
74
+ _userEvent["default"].click(svg);
75
+ expect(input).not.toBeChecked();
76
+ expect(onChange).toHaveBeenNthCalledWith(2, false);
77
+ });
60
78
  test('isSelected for controlled checkbox', function () {
61
79
  getComponent({
62
80
  isSelected: true
@@ -68,6 +86,21 @@ test('isSelected for controlled checkbox', function () {
68
86
  _userEvent["default"].click(input);
69
87
  expect(input).toBeChecked();
70
88
  });
89
+ test('isSelected for controlled checkbox, clicking svg', function () {
90
+ getComponent({
91
+ isSelected: true,
92
+ checkBoxProps: {
93
+ 'data-testid': 'checkbox-icon'
94
+ }
95
+ });
96
+ var input = _testWrapper.screen.getByRole('checkbox');
97
+ var svg = _testWrapper.screen.getByTestId('checkbox-icon');
98
+ expect(input).toBeChecked();
99
+
100
+ // Ensure it is controlled.
101
+ _userEvent["default"].click(svg);
102
+ expect(input).toBeChecked();
103
+ });
71
104
  test('defaultValue for uncontrolled checkbox', function () {
72
105
  getComponent({
73
106
  isDefaultSelected: true
@@ -79,6 +112,21 @@ test('defaultValue for uncontrolled checkbox', function () {
79
112
  _userEvent["default"].click(input);
80
113
  expect(input).not.toBeChecked();
81
114
  });
115
+ test('defaultValue for uncontrolled checkbox, clicking svg', function () {
116
+ getComponent({
117
+ isDefaultSelected: true,
118
+ checkBoxProps: {
119
+ 'data-testid': 'checkbox-icon'
120
+ }
121
+ });
122
+ var input = _testWrapper.screen.getByRole('checkbox');
123
+ var svg = _testWrapper.screen.getByTestId('checkbox-icon');
124
+ expect(input).toBeChecked();
125
+
126
+ // Ensure it is uncontrolled.
127
+ _userEvent["default"].click(svg);
128
+ expect(input).not.toBeChecked();
129
+ });
82
130
  test('name for checkbox', function () {
83
131
  var name = 'custom';
84
132
  getComponent({
@@ -135,4 +183,34 @@ test('indeterminate checkbox', function () {
135
183
  // Ensure it can be changed via user interaction, should be unchecked now
136
184
  _userEvent["default"].click(input);
137
185
  expect(input).not.toBeChecked();
186
+ });
187
+ test('indeterminate checkbox, clicking svg', function () {
188
+ var _getComponent2 = getComponent({
189
+ isIndeterminate: true,
190
+ checkBoxProps: {
191
+ 'data-testid': 'checkbox-icon'
192
+ }
193
+ }),
194
+ rerender = _getComponent2.rerender;
195
+ var input = _testWrapper.screen.getByRole('checkbox');
196
+ var svg = _testWrapper.screen.getByTestId('checkbox-icon-indeterminate');
197
+ var label = _testWrapper.screen.getByText(testLabel);
198
+ /* eslint-disable jest-dom/prefer-checked */
199
+ expect(input).toHaveAttribute('aria-checked', 'mixed');
200
+ expect(label).toHaveClass('is-indeterminate');
201
+
202
+ // Ensure it cannot be changed via user interaction
203
+ _userEvent["default"].click(svg);
204
+ expect(input).toHaveAttribute('aria-checked', 'mixed');
205
+ // An indeterminite checkbox can still have the checked attribute
206
+ expect(input).toBeChecked();
207
+
208
+ // Ensure it works normally when toggled off again
209
+ getComponent({}, {
210
+ renderFn: rerender
211
+ });
212
+ // Reset the variable since the DOM has changed
213
+ input = _testWrapper.screen.getByRole('checkbox');
214
+ expect(input).not.toHaveAttribute('aria-checked', 'mixed');
215
+ expect(label).not.toHaveClass('is-indeterminate');
138
216
  });
@@ -6,4 +6,6 @@ export interface CheckboxFieldProps extends Omit<UseFieldProps<HTMLInputElement>
6
6
  onKeyUp?: () => void;
7
7
  /** Handler that is called when the element's selection state changes. */
8
8
  onChange?: (isSelected: boolean) => void;
9
+ /** props that are spread directly into the checkbox component */
10
+ checkBoxProps?: object;
9
11
  }
@@ -29,8 +29,9 @@ var IndeterminateCheckboxIcon = function IndeterminateCheckboxIcon(props) {
29
29
  viewBox: "0 0 24 24",
30
30
  fill: "none",
31
31
  xmlns: "http://www.w3.org/2000/svg",
32
- "aria-labelledby": "checkbox-icon-title"
33
- }, omit(props, 'id', 'aria-checked')), ___EmotionJSX("title", {
32
+ "aria-labelledby": "checkbox-icon-title",
33
+ "data-testid": "checkbox-icon-indeterminate"
34
+ }, omit(props, 'id', 'aria-checked', 'data-testid')), ___EmotionJSX("title", {
34
35
  id: "checkbox-icon-title"
35
36
  }, "Indeterminate Checkbox Icon"), ___EmotionJSX("rect", {
36
37
  x: "3.5",
@@ -11,7 +11,7 @@ import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
11
11
  function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
12
12
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
13
13
  import React, { forwardRef, useEffect, useMemo } from 'react';
14
- import { useCheckbox } from 'react-aria';
14
+ import { mergeProps, useCheckbox } from 'react-aria';
15
15
  import { useToggleState } from 'react-stately';
16
16
  import { usePress } from '@react-aria/interactions';
17
17
  import { v4 as uuid } from 'uuid';
@@ -23,6 +23,7 @@ import { jsx as ___EmotionJSX } from "@emotion/react";
23
23
  var displayName = 'CheckboxField';
24
24
  var CheckboxField = /*#__PURE__*/forwardRef(function (props, ref) {
25
25
  var label = props.label,
26
+ checkBoxProps = props.checkBoxProps,
26
27
  _props$controlProps = props.controlProps,
27
28
  controlProps = _props$controlProps === void 0 ? {} : _props$controlProps,
28
29
  hasAutoFocus = props.hasAutoFocus,
@@ -73,7 +74,7 @@ var CheckboxField = /*#__PURE__*/forwardRef(function (props, ref) {
73
74
  }, fieldLabelProps), ___EmotionJSX(Checkbox, _extends({
74
75
  ref: checkboxRef,
75
76
  "aria-describedby": helperText && helperTextId
76
- }, fieldControlInputProps)), label)), helperText && ___EmotionJSX(FieldHelperText, {
77
+ }, mergeProps(fieldControlInputProps, checkBoxProps))), label)), helperText && ___EmotionJSX(FieldHelperText, {
77
78
  status: status,
78
79
  sx: {
79
80
  pt: 7
@@ -54,6 +54,24 @@ test('checkbox interaction', function () {
54
54
  expect(input).not.toBeChecked();
55
55
  expect(onChange).toHaveBeenNthCalledWith(2, false);
56
56
  });
57
+ test('checkbox interaction on svg', function () {
58
+ var onChange = jest.fn();
59
+ getComponent({
60
+ onChange: onChange,
61
+ checkBoxProps: {
62
+ 'data-testid': 'checkbox-icon'
63
+ }
64
+ });
65
+ var input = screen.getByRole('checkbox');
66
+ var svg = screen.getByTestId('checkbox-icon');
67
+ expect(onChange).not.toHaveBeenCalled();
68
+ userEvent.click(svg);
69
+ expect(input).toBeChecked();
70
+ expect(onChange).toHaveBeenNthCalledWith(1, true);
71
+ userEvent.click(svg);
72
+ expect(input).not.toBeChecked();
73
+ expect(onChange).toHaveBeenNthCalledWith(2, false);
74
+ });
57
75
  test('isSelected for controlled checkbox', function () {
58
76
  getComponent({
59
77
  isSelected: true
@@ -65,6 +83,21 @@ test('isSelected for controlled checkbox', function () {
65
83
  userEvent.click(input);
66
84
  expect(input).toBeChecked();
67
85
  });
86
+ test('isSelected for controlled checkbox, clicking svg', function () {
87
+ getComponent({
88
+ isSelected: true,
89
+ checkBoxProps: {
90
+ 'data-testid': 'checkbox-icon'
91
+ }
92
+ });
93
+ var input = screen.getByRole('checkbox');
94
+ var svg = screen.getByTestId('checkbox-icon');
95
+ expect(input).toBeChecked();
96
+
97
+ // Ensure it is controlled.
98
+ userEvent.click(svg);
99
+ expect(input).toBeChecked();
100
+ });
68
101
  test('defaultValue for uncontrolled checkbox', function () {
69
102
  getComponent({
70
103
  isDefaultSelected: true
@@ -76,6 +109,21 @@ test('defaultValue for uncontrolled checkbox', function () {
76
109
  userEvent.click(input);
77
110
  expect(input).not.toBeChecked();
78
111
  });
112
+ test('defaultValue for uncontrolled checkbox, clicking svg', function () {
113
+ getComponent({
114
+ isDefaultSelected: true,
115
+ checkBoxProps: {
116
+ 'data-testid': 'checkbox-icon'
117
+ }
118
+ });
119
+ var input = screen.getByRole('checkbox');
120
+ var svg = screen.getByTestId('checkbox-icon');
121
+ expect(input).toBeChecked();
122
+
123
+ // Ensure it is uncontrolled.
124
+ userEvent.click(svg);
125
+ expect(input).not.toBeChecked();
126
+ });
79
127
  test('name for checkbox', function () {
80
128
  var name = 'custom';
81
129
  getComponent({
@@ -132,4 +180,34 @@ test('indeterminate checkbox', function () {
132
180
  // Ensure it can be changed via user interaction, should be unchecked now
133
181
  userEvent.click(input);
134
182
  expect(input).not.toBeChecked();
183
+ });
184
+ test('indeterminate checkbox, clicking svg', function () {
185
+ var _getComponent2 = getComponent({
186
+ isIndeterminate: true,
187
+ checkBoxProps: {
188
+ 'data-testid': 'checkbox-icon'
189
+ }
190
+ }),
191
+ rerender = _getComponent2.rerender;
192
+ var input = screen.getByRole('checkbox');
193
+ var svg = screen.getByTestId('checkbox-icon-indeterminate');
194
+ var label = screen.getByText(testLabel);
195
+ /* eslint-disable jest-dom/prefer-checked */
196
+ expect(input).toHaveAttribute('aria-checked', 'mixed');
197
+ expect(label).toHaveClass('is-indeterminate');
198
+
199
+ // Ensure it cannot be changed via user interaction
200
+ userEvent.click(svg);
201
+ expect(input).toHaveAttribute('aria-checked', 'mixed');
202
+ // An indeterminite checkbox can still have the checked attribute
203
+ expect(input).toBeChecked();
204
+
205
+ // Ensure it works normally when toggled off again
206
+ getComponent({}, {
207
+ renderFn: rerender
208
+ });
209
+ // Reset the variable since the DOM has changed
210
+ input = screen.getByRole('checkbox');
211
+ expect(input).not.toHaveAttribute('aria-checked', 'mixed');
212
+ expect(label).not.toHaveClass('is-indeterminate');
135
213
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pingux/astro",
3
- "version": "2.93.0-alpha.3",
3
+ "version": "2.93.0-alpha.4",
4
4
  "description": "React component library for Ping Identity's design system",
5
5
  "repository": {
6
6
  "type": "git",