@automattic/vip-design-system 2.10.4 → 2.11.1

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.
@@ -13,6 +13,7 @@ export declare enum ButtonVariant {
13
13
  }
14
14
  export interface ButtonProps extends ThemeButtonProps {
15
15
  disabled?: boolean;
16
+ preferAriaDisabled?: boolean;
16
17
  onClick?: (event: ButtonClickType) => void;
17
18
  full?: boolean;
18
19
  grow?: boolean;
@@ -1,4 +1,4 @@
1
- var _excluded = ["className", "disabled", "onClick", "sx", "full", "grow"];
1
+ var _excluded = ["className", "disabled", "preferAriaDisabled", "onClick", "sx", "full", "grow"];
2
2
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
3
3
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
4
4
  import classNames from 'classnames';
@@ -19,13 +19,19 @@ export var ButtonVariant = /*#__PURE__*/function (ButtonVariant) {
19
19
  var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
20
20
  var className = _ref.className,
21
21
  disabled = _ref.disabled,
22
+ preferAriaDisabled = _ref.preferAriaDisabled,
22
23
  onClick = _ref.onClick,
23
24
  sx = _ref.sx,
24
25
  full = _ref.full,
25
26
  grow = _ref.grow,
26
27
  rest = _objectWithoutPropertiesLoose(_ref, _excluded);
28
+ var disabledAttributes = disabled && preferAriaDisabled === true ? {
29
+ 'aria-disabled': true
30
+ } : {
31
+ disabled: disabled
32
+ };
27
33
  var handleOnClick = useCallback(function (event) {
28
- if (disabled) {
34
+ if (preferAriaDisabled && disabled) {
29
35
  return event.preventDefault();
30
36
  }
31
37
  if (onClick) {
@@ -38,7 +44,7 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
38
44
  '&:focus-visible': function focusVisible(theme) {
39
45
  return theme.outline;
40
46
  },
41
- '&[aria-disabled="true"]': {
47
+ '&[disabled], &[aria-disabled="true"]': {
42
48
  opacity: 0.7,
43
49
  backgroundColor: 'input.border.disabled',
44
50
  color: 'texts.secondary',
@@ -51,8 +57,7 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
51
57
  flexGrow: Boolean(grow) === true ? '1' : undefined,
52
58
  width: Boolean(full) === true ? '100%' : undefined
53
59
  }, sx)
54
- }, rest, {
55
- "aria-disabled": disabled,
60
+ }, rest, disabledAttributes, {
56
61
  onClick: handleOnClick,
57
62
  className: classNames('vip-button-component', className),
58
63
  ref: ref
@@ -32,3 +32,4 @@ declare const _default: {
32
32
  };
33
33
  export default _default;
34
34
  export declare const Default: (args: any) => React.JSX.Element;
35
+ export declare const PreferAriaDisabled: (args: any) => React.JSX.Element;
@@ -138,4 +138,14 @@ var Template = function Template(args) {
138
138
  })]
139
139
  });
140
140
  };
141
- export var Default = Template.bind({});
141
+ var PreferAriaDisabledTemplate = function PreferAriaDisabledTemplate(args) {
142
+ return _jsx("div", {
143
+ children: _jsx(Button, _extends({}, args, {
144
+ disabled: true,
145
+ preferAriaDisabled: true,
146
+ children: "Primary"
147
+ }))
148
+ });
149
+ };
150
+ export var Default = Template.bind({});
151
+ export var PreferAriaDisabled = PreferAriaDisabledTemplate.bind({});
@@ -55,8 +55,8 @@ describe('<Button />', function () {
55
55
  })), container = _render2.container;
56
56
  component = screen.getByText(BUTTON_TEXT);
57
57
  expect(component).toBeInTheDocument();
58
- expect(component).toHaveAttribute('aria-disabled', 'true');
59
- expect(component).not.toHaveAttribute('disabled');
58
+ expect(component).toHaveAttribute('disabled', '');
59
+ expect(component).not.toHaveAttribute('aria-disabled');
60
60
  fireEvent.click(component);
61
61
  expect(onClick).toHaveBeenCalledTimes(0);
62
62
 
@@ -73,4 +73,36 @@ describe('<Button />', function () {
73
73
  }
74
74
  }, _callee2);
75
75
  })));
76
+ it('renders the Button with aria-disabled prop', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
77
+ var onClick, _render3, container, component;
78
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
79
+ while (1) switch (_context3.prev = _context3.next) {
80
+ case 0:
81
+ onClick = jest.fn(function () {});
82
+ _render3 = render(_jsx(Button, {
83
+ disabled: true,
84
+ preferAriaDisabled: true,
85
+ onClick: onClick,
86
+ children: BUTTON_TEXT
87
+ })), container = _render3.container;
88
+ component = screen.getByText(BUTTON_TEXT);
89
+ expect(component).toBeInTheDocument();
90
+ expect(component).toHaveAttribute('aria-disabled', 'true');
91
+ expect(component).not.toHaveAttribute('disabled');
92
+ fireEvent.click(component);
93
+ expect(onClick).toHaveBeenCalledTimes(0);
94
+
95
+ // Check for accessibility issues
96
+ _context3.t0 = expect;
97
+ _context3.next = 11;
98
+ return axe(container);
99
+ case 11:
100
+ _context3.t1 = _context3.sent;
101
+ (0, _context3.t0)(_context3.t1).toHaveNoViolations();
102
+ case 13:
103
+ case "end":
104
+ return _context3.stop();
105
+ }
106
+ }, _callee3);
107
+ })));
76
108
  });
@@ -46,6 +46,7 @@ export var ButtonSubmit = /*#__PURE__*/React.forwardRef(function (_ref2, ref) {
46
46
  ref: ref,
47
47
  className: classNames('vip-button-submit-component', "vip-button-submit-" + variant),
48
48
  disabled: disabled || loading,
49
+ preferAriaDisabled: true,
49
50
  variant: variant,
50
51
  "aria-busy": loading
51
52
  }, rest, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/vip-design-system",
3
- "version": "2.10.4",
3
+ "version": "2.11.1",
4
4
  "main": "build/system/index.js",
5
5
  "scripts": {
6
6
  "build-storybook": "storybook build",
@@ -119,4 +119,13 @@ const Template = args => (
119
119
  </div>
120
120
  );
121
121
 
122
+ const PreferAriaDisabledTemplate = args => (
123
+ <div>
124
+ <Button { ...args } disabled preferAriaDisabled>
125
+ Primary
126
+ </Button>
127
+ </div>
128
+ );
129
+
122
130
  export const Default = Template.bind( {} );
131
+ export const PreferAriaDisabled = PreferAriaDisabledTemplate.bind( {} );
@@ -33,6 +33,28 @@ describe( '<Button />', () => {
33
33
  { BUTTON_TEXT }
34
34
  </Button>
35
35
  );
36
+
37
+ const component = screen.getByText( BUTTON_TEXT );
38
+
39
+ expect( component ).toBeInTheDocument();
40
+ expect( component ).toHaveAttribute( 'disabled', '' );
41
+ expect( component ).not.toHaveAttribute( 'aria-disabled' );
42
+
43
+ fireEvent.click( component );
44
+ expect( onClick ).toHaveBeenCalledTimes( 0 );
45
+
46
+ // Check for accessibility issues
47
+ expect( await axe( container ) ).toHaveNoViolations();
48
+ } );
49
+
50
+ it( 'renders the Button with aria-disabled prop', async () => {
51
+ const onClick = jest.fn( () => {} );
52
+ const { container } = render(
53
+ <Button disabled preferAriaDisabled onClick={ onClick }>
54
+ { BUTTON_TEXT }
55
+ </Button>
56
+ );
57
+
36
58
  const component = screen.getByText( BUTTON_TEXT );
37
59
 
38
60
  expect( component ).toBeInTheDocument();
@@ -21,6 +21,7 @@ export enum ButtonVariant {
21
21
 
22
22
  export interface ButtonProps extends ThemeButtonProps {
23
23
  disabled?: boolean;
24
+ preferAriaDisabled?: boolean;
24
25
  onClick?: ( event: ButtonClickType ) => void;
25
26
  full?: boolean;
26
27
  grow?: boolean;
@@ -28,10 +29,13 @@ export interface ButtonProps extends ThemeButtonProps {
28
29
  }
29
30
 
30
31
  const Button = forwardRef< HTMLButtonElement, ButtonProps >(
31
- ( { className, disabled, onClick, sx, full, grow, ...rest }, ref ) => {
32
+ ( { className, disabled, preferAriaDisabled, onClick, sx, full, grow, ...rest }, ref ) => {
33
+ const disabledAttributes =
34
+ disabled && preferAriaDisabled === true ? { 'aria-disabled': true } : { disabled };
35
+
32
36
  const handleOnClick = useCallback(
33
37
  ( event: ButtonClickType ) => {
34
- if ( disabled ) {
38
+ if ( preferAriaDisabled && disabled ) {
35
39
  return event.preventDefault();
36
40
  }
37
41
 
@@ -47,7 +51,7 @@ const Button = forwardRef< HTMLButtonElement, ButtonProps >(
47
51
  sx={ {
48
52
  '&:focus': 'none',
49
53
  '&:focus-visible': ( theme: ButtonTheme ) => theme.outline,
50
- '&[aria-disabled="true"]': {
54
+ '&[disabled], &[aria-disabled="true"]': {
51
55
  opacity: 0.7,
52
56
  backgroundColor: 'input.border.disabled',
53
57
  color: 'texts.secondary',
@@ -62,7 +66,7 @@ const Button = forwardRef< HTMLButtonElement, ButtonProps >(
62
66
  ...sx,
63
67
  } }
64
68
  { ...rest }
65
- aria-disabled={ disabled }
69
+ { ...disabledAttributes }
66
70
  onClick={ handleOnClick }
67
71
  className={ classNames( 'vip-button-component', className ) }
68
72
  ref={ ref }
@@ -49,6 +49,7 @@ export const ButtonSubmit = React.forwardRef< HTMLButtonElement, ButtonSubmitPro
49
49
  ref={ ref }
50
50
  className={ classNames( 'vip-button-submit-component', `vip-button-submit-${ variant }` ) }
51
51
  disabled={ disabled || loading }
52
+ preferAriaDisabled={ true }
52
53
  variant={ variant }
53
54
  aria-busy={ loading }
54
55
  { ...rest }