@canonical/react-components 0.54.0 → 0.56.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.
@@ -20,11 +20,11 @@ export type Props = {
20
20
  * An optional key to be used to track which section is selected.
21
21
  */
22
22
  sectionKey?: string;
23
- setExpanded?: (key: string | null, title: string | null) => void;
23
+ setExpanded?: (key: string | null, title: ReactNode | null) => void;
24
24
  /**
25
25
  * The title of the section.
26
26
  */
27
- title?: string;
27
+ title?: ReactNode;
28
28
  /**
29
29
  * Optional string describing heading element that should be used for the section titles.
30
30
  */
@@ -56,6 +56,10 @@ export type Props = PropsWithSpread<{
56
56
  * Optional class(es) to pass to the wrapping Field component
57
57
  */
58
58
  wrapperClassName?: string;
59
+ /**
60
+ * Function to occur on keyboard event, 'CTRL + Enter'
61
+ */
62
+ onControlEnter?: () => void;
59
63
  }, TextareaHTMLAttributes<HTMLTextAreaElement>>;
60
- declare const Textarea: ({ caution, className, error, grow, help, id, label, labelClassName, onKeyUp, required, stacked, style, success, takeFocus, wrapperClassName, ...props }: Props) => JSX.Element;
64
+ declare const Textarea: ({ caution, className, error, grow, help, id, label, labelClassName, onKeyUp, onControlEnter, required, stacked, style, success, takeFocus, wrapperClassName, ...props }: Props) => JSX.Element;
61
65
  export default Textarea;
@@ -27,6 +27,7 @@ const Textarea = _ref => {
27
27
  label,
28
28
  labelClassName,
29
29
  onKeyUp,
30
+ onControlEnter,
30
31
  required,
31
32
  stacked,
32
33
  style,
@@ -42,6 +43,17 @@ const Textarea = _ref => {
42
43
  const [innerValue, setInnervalue] = (0, _react.useState)(props.defaultValue);
43
44
  const defaultTextAreaId = (0, _react.useId)();
44
45
  const textAreaId = id || defaultTextAreaId;
46
+ const handleKeyDown = (0, _react.useCallback)(event => {
47
+ if (event.key === "Enter" && (event.ctrlKey || event.metaKey) && document.activeElement === textareaRef.current) {
48
+ onControlEnter();
49
+ }
50
+ }, [onControlEnter]);
51
+ (0, _react.useEffect)(() => {
52
+ document.addEventListener("keydown", handleKeyDown);
53
+ return () => {
54
+ document.removeEventListener("keydown", handleKeyDown);
55
+ };
56
+ }, [handleKeyDown]);
45
57
  (0, _react.useEffect)(() => {
46
58
  if (takeFocus) {
47
59
  textareaRef.current.focus();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canonical/react-components",
3
- "version": "0.54.0",
3
+ "version": "0.56.0",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "author": "Huw Wilkins <huw.wilkins@canonical.com>",