@conduction/components 2.2.56 → 2.2.57

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.
package/README.md CHANGED
@@ -4,6 +4,10 @@
4
4
 
5
5
  - **Version 2.2 (breaking changes from 2.1.x)**
6
6
 
7
+ - 2.2.57:
8
+ - Fixed clear button on SelectSingle not being clickable with keyboard functions.
9
+ - Fixed Logo not being focusable when being clickable.
10
+ - Fixed CardWrapper not being clickable with keyboard functions
7
11
  - 2.2.56: Fixed WCAG issue in Pagination by adding aria labels to buttons
8
12
  - 2.2.55:
9
13
  - Updated Logo to accept aria-label for accessibility.
@@ -1,6 +1,18 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import * as styles from "./CardWrapper.module.css";
3
3
  export const CardWrapper = (props) => {
4
- const _props = { ...props, className: `${props.className} ${styles.container}` };
4
+ const handleKeyDown = (event) => {
5
+ if (props.onClick && (event.key === "Enter" || event.key === " ")) {
6
+ event.preventDefault();
7
+ props.onClick(event);
8
+ }
9
+ };
10
+ const _props = {
11
+ ...props,
12
+ className: `${props.className} ${styles.container}`,
13
+ role: props.onClick ? "button" : undefined,
14
+ tabIndex: props.onClick ? 0 : undefined,
15
+ ...(props.onClick && { onKeyDown: handleKeyDown }),
16
+ };
5
17
  return _jsx("div", { ..._props, children: props.children });
6
18
  };
@@ -3,7 +3,7 @@ import * as React from "react";
3
3
  import * as styles from "./select.module.css";
4
4
  import clsx from "clsx";
5
5
  import CreatableSelect from "react-select/creatable";
6
- import ReactSelect from "react-select";
6
+ import ReactSelect, { components } from "react-select";
7
7
  import { Controller } from "react-hook-form";
8
8
  import { ErrorMessage } from "../errorMessage/ErrorMessage";
9
9
  const selectStyles = {
@@ -95,6 +95,29 @@ const setAttributes = () => {
95
95
  });
96
96
  }, 100);
97
97
  };
98
+ // Custom ClearIndicator component that handles keyboard events for accessibility
99
+ const ClearIndicator = (props) => {
100
+ const { clearValue, innerProps, children } = props;
101
+ const handleKeyDown = (event) => {
102
+ if (event.key === " " || event.key === "Enter") {
103
+ event.preventDefault();
104
+ event.stopPropagation();
105
+ if (clearValue) {
106
+ clearValue();
107
+ }
108
+ if (innerProps?.onClick) {
109
+ innerProps.onClick(event);
110
+ }
111
+ }
112
+ else if (innerProps?.onKeyDown) {
113
+ innerProps.onKeyDown(event);
114
+ }
115
+ };
116
+ return (_jsx(components.ClearIndicator, { ...props, innerProps: {
117
+ ...innerProps,
118
+ onKeyDown: handleKeyDown,
119
+ }, children: children }));
120
+ };
98
121
  export const SelectMultiple = ({ id, name, options, errors, control, validation, defaultValue, disabled, hideErrorMessage, menuPlacement, placeholder, ariaLabel, }) => {
99
122
  React.useEffect(() => {
100
123
  setAttributes();
@@ -116,7 +139,7 @@ export const SelectSingle = ({ id, name, options, errors, control, validation, i
116
139
  setAttributes();
117
140
  }, []);
118
141
  return (_jsx(Controller, { control, name, defaultValue, rules: validation, render: ({ field: { onChange, value } }) => {
119
- return (_jsxs(_Fragment, { children: [_jsx(ReactSelect, { "aria-label": ariaLabel, inputId: id, value: value ?? "", className: clsx(styles.select, errors[name] && styles.error), isDisabled: disabled, options, onChange, errors, isClearable, menuPortalTarget: document.body, menuPlacement: menuPlacement, styles: selectStyles, placeholder: disabled ? "Disabled..." : placeholder ?? "Select one or more options...", formatGroupLabel: (group) => _jsx(GroupLabel, { group }) }), errors[name] && !hideErrorMessage && _jsx(ErrorMessage, { message: errors[name]?.message })] }));
142
+ return (_jsxs(_Fragment, { children: [_jsx(ReactSelect, { "aria-label": ariaLabel, inputId: id, value: value ?? "", className: clsx(styles.select, errors[name] && styles.error), isDisabled: disabled, options, onChange, errors, isClearable, menuPortalTarget: document.body, menuPlacement: menuPlacement, styles: selectStyles, placeholder: disabled ? "Disabled..." : placeholder ?? "Select one or more options...", formatGroupLabel: (group) => _jsx(GroupLabel, { group }), components: isClearable ? { ClearIndicator } : undefined }), errors[name] && !hideErrorMessage && _jsx(ErrorMessage, { message: errors[name]?.message })] }));
120
143
  } }));
121
144
  };
122
145
  const GroupLabel = ({ group }) => {
@@ -2,8 +2,14 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import * as styles from "./Logo.module.css";
3
3
  import clsx from "clsx";
4
4
  export const Logo = ({ onClick, layoutClassName, variant = "header", ariaLabel = "logo" }) => {
5
+ const handleKeyDown = (event) => {
6
+ if (onClick && (event.key === "Enter" || event.key === " ")) {
7
+ event.preventDefault();
8
+ onClick();
9
+ }
10
+ };
5
11
  return (_jsx("div", { className: clsx(styles.container, styles[variant], [
6
12
  onClick && styles.clickable,
7
13
  layoutClassName && layoutClassName,
8
- ]), role: "img", "aria-label": ariaLabel, onClick }));
14
+ ]), role: onClick ? "button" : "img", "aria-label": ariaLabel, tabIndex: onClick ? 0 : undefined, onClick, ...(onClick && { onKeyDown: handleKeyDown }) }));
9
15
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@conduction/components",
3
- "version": "2.2.56",
3
+ "version": "2.2.57",
4
4
  "description": "React (Gatsby) components used within the Conduction Skeleton Application (and its implementations)",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -2,7 +2,20 @@ import * as React from "react";
2
2
  import * as styles from "./CardWrapper.module.css";
3
3
 
4
4
  export const CardWrapper = (props: React.HTMLAttributes<HTMLDivElement>): JSX.Element => {
5
- const _props = { ...props, className: `${props.className} ${styles.container}` };
5
+ const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
6
+ if (props.onClick && (event.key === "Enter" || event.key === " ")) {
7
+ event.preventDefault();
8
+ props.onClick(event as any);
9
+ }
10
+ };
11
+
12
+ const _props = {
13
+ ...props,
14
+ className: `${props.className} ${styles.container}`,
15
+ role: props.onClick ? "button" : undefined,
16
+ tabIndex: props.onClick ? 0 : undefined,
17
+ ...(props.onClick && { onKeyDown: handleKeyDown }),
18
+ };
6
19
 
7
20
  return <div {..._props}>{props.children}</div>;
8
21
  };
@@ -2,7 +2,7 @@ import * as React from "react";
2
2
  import * as styles from "./select.module.css";
3
3
  import clsx from "clsx";
4
4
  import CreatableSelect from "react-select/creatable";
5
- import ReactSelect, { MenuPlacement, StylesConfig, GroupBase } from "react-select";
5
+ import ReactSelect, { MenuPlacement, StylesConfig, GroupBase, components } from "react-select";
6
6
  import { Control, Controller, FieldValues } from "react-hook-form";
7
7
  import { IReactHookFormProps } from "../types";
8
8
  import { ErrorMessage } from "../errorMessage/ErrorMessage";
@@ -122,6 +122,38 @@ const setAttributes = (): void => {
122
122
  }, 100);
123
123
  };
124
124
 
125
+ // Custom ClearIndicator component that handles keyboard events for accessibility
126
+ const ClearIndicator = (props: any) => {
127
+ const { clearValue, innerProps, children } = props;
128
+
129
+ const handleKeyDown = (event: React.KeyboardEvent) => {
130
+ if (event.key === " " || event.key === "Enter") {
131
+ event.preventDefault();
132
+ event.stopPropagation();
133
+ if (clearValue) {
134
+ clearValue();
135
+ }
136
+ if (innerProps?.onClick) {
137
+ innerProps.onClick(event);
138
+ }
139
+ } else if (innerProps?.onKeyDown) {
140
+ innerProps.onKeyDown(event);
141
+ }
142
+ };
143
+
144
+ return (
145
+ <components.ClearIndicator
146
+ {...props}
147
+ innerProps={{
148
+ ...innerProps,
149
+ onKeyDown: handleKeyDown,
150
+ }}
151
+ >
152
+ {children}
153
+ </components.ClearIndicator>
154
+ );
155
+ };
156
+
125
157
  export const SelectMultiple = ({
126
158
  id,
127
159
  name,
@@ -251,6 +283,7 @@ export const SelectSingle = ({
251
283
  styles={selectStyles}
252
284
  placeholder={disabled ? "Disabled..." : placeholder ?? "Select one or more options..."}
253
285
  formatGroupLabel={(group) => <GroupLabel {...{ group }} />}
286
+ components={isClearable ? { ClearIndicator } : undefined}
254
287
  />
255
288
  {errors[name] && !hideErrorMessage && <ErrorMessage message={errors[name]?.message as string} />}
256
289
  </>
@@ -10,15 +10,24 @@ interface LogoProps {
10
10
  }
11
11
 
12
12
  export const Logo: React.FC<LogoProps> = ({ onClick, layoutClassName, variant = "header", ariaLabel = "logo" }) => {
13
+ const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
14
+ if (onClick && (event.key === "Enter" || event.key === " ")) {
15
+ event.preventDefault();
16
+ onClick();
17
+ }
18
+ };
19
+
13
20
  return (
14
21
  <div
15
22
  className={clsx(styles.container, styles[variant], [
16
23
  onClick && styles.clickable,
17
24
  layoutClassName && layoutClassName,
18
25
  ])}
19
- role="img"
26
+ role={onClick ? "button" : "img"}
20
27
  aria-label={ariaLabel}
28
+ tabIndex={onClick ? 0 : undefined}
21
29
  {...{ onClick }}
30
+ {...(onClick && { onKeyDown: handleKeyDown })}
22
31
  />
23
32
  );
24
33
  };