@canonical/react-components 0.37.6 → 0.37.7

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.
@@ -65,24 +65,20 @@ var NavigationMenu = function NavigationMenu(_ref) {
65
65
  var closeMenu = (0, _react.useCallback)(function () {
66
66
  return setIsOpen(false);
67
67
  }, [setIsOpen]);
68
-
69
- var _useClickOutside = (0, _hooks.useClickOutside)(closeMenu),
70
- _useClickOutside2 = _slicedToArray(_useClickOutside, 2),
71
- menuRef = _useClickOutside2[0],
72
- menuId = _useClickOutside2[1];
73
-
68
+ var menuRef = (0, _hooks.useClickOutside)(closeMenu);
69
+ var menuId = (0, _hooks.useId)();
74
70
  return /*#__PURE__*/_react.default.createElement("li", _extends({}, props, {
75
71
  className: (0, _classnames.default)(props.className, "p-navigation__item--dropdown-toggle", {
76
72
  "is-active": isOpen
77
- })
73
+ }),
74
+ ref: menuRef
78
75
  }), /*#__PURE__*/_react.default.createElement("button", {
79
76
  "aria-controls": menuId,
80
77
  className: "p-navigation__link u-no-margin--right",
81
78
  onClick: function onClick(evt) {
82
79
  evt.preventDefault();
83
80
  setIsOpen(!isOpen);
84
- },
85
- ref: menuRef
81
+ }
86
82
  }, label), /*#__PURE__*/_react.default.createElement("ul", {
87
83
  "aria-hidden": !isOpen,
88
84
  className: (0, _classnames.default)("p-navigation__dropdown", {
@@ -25,7 +25,8 @@ var PaginationButton = function PaginationButton(_ref) {
25
25
  "p-pagination__link--next": direction === "forward"
26
26
  }),
27
27
  disabled: disabled,
28
- onClick: onClick
28
+ onClick: onClick,
29
+ type: "button"
29
30
  }, /*#__PURE__*/_react.default.createElement("i", {
30
31
  className: "p-icon--chevron-down"
31
32
  }, label)));
@@ -23,7 +23,8 @@ var PaginationItem = function PaginationItem(_ref) {
23
23
  "is-active": isActive
24
24
  }),
25
25
  onClick: onClick,
26
- "aria-current": isActive ? "page" : undefined
26
+ "aria-current": isActive ? "page" : undefined,
27
+ type: "button"
27
28
  }, number));
28
29
  };
29
30
 
@@ -1,7 +1,6 @@
1
1
  import { MutableRefObject } from "react";
2
2
  /**
3
3
  * Handle clicks outside an element.
4
- * @returns An id and ref to pass to the element to handle clicks
5
- * outside of.
4
+ * @returns A ref to pass to the element to handle clicks outside of.
6
5
  */
7
- export declare const useClickOutside: <E extends HTMLElement>(onClickOutside: () => void) => [MutableRefObject<E>, string];
6
+ export declare const useClickOutside: <E extends HTMLElement>(onClickOutside: () => void) => MutableRefObject<E>;
@@ -7,35 +7,31 @@ exports.useClickOutside = void 0;
7
7
 
8
8
  var _react = require("react");
9
9
 
10
- var _useId = require("./useId");
11
-
12
10
  /**
13
11
  * Handle clicks outside an element.
14
- * @returns An id and ref to pass to the element to handle clicks
15
- * outside of.
12
+ * @returns A ref to pass to the element to handle clicks outside of.
16
13
  */
17
14
  var useClickOutside = function useClickOutside(onClickOutside) {
18
- var wrapperRef = (0, _react.useRef)(null);
19
- var id = (0, _useId.useId)();
15
+ var ref = (0, _react.useRef)(null);
20
16
  var handleClickOutside = (0, _react.useCallback)(function (evt) {
21
- var _evt$target, _wrapperRef$current;
17
+ var _evt$target, _ref$current;
22
18
 
23
19
  var target = evt.target; // The target might be something like an SVG node which doesn't provide
24
20
  // the class name as a string.
25
21
 
26
22
  var isValidTarget = typeof (evt === null || evt === void 0 ? void 0 : (_evt$target = evt.target) === null || _evt$target === void 0 ? void 0 : _evt$target.className) === "string";
27
23
 
28
- if (!isValidTarget || wrapperRef.current && !((_wrapperRef$current = wrapperRef.current) !== null && _wrapperRef$current !== void 0 && _wrapperRef$current.contains(target)) && target.id !== id) {
24
+ if (!isValidTarget || ref.current && !((_ref$current = ref.current) !== null && _ref$current !== void 0 && _ref$current.contains(target)) && ref.current !== target) {
29
25
  onClickOutside();
30
26
  }
31
- }, [id, onClickOutside]);
27
+ }, [onClickOutside]);
32
28
  (0, _react.useEffect)(function () {
33
29
  document.addEventListener("click", handleClickOutside, false);
34
30
  return function () {
35
31
  return document.removeEventListener("click", handleClickOutside, false);
36
32
  };
37
33
  }, [handleClickOutside]);
38
- return [wrapperRef, id];
34
+ return ref;
39
35
  };
40
36
 
41
37
  exports.useClickOutside = useClickOutside;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canonical/react-components",
3
- "version": "0.37.6",
3
+ "version": "0.37.7",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "author": "Huw Wilkins <huw.wilkins@canonical.com>",
@@ -83,7 +83,7 @@
83
83
  "ts-jest": "27.1.5",
84
84
  "tsc-alias": "1.7.0",
85
85
  "typescript": "4.7.4",
86
- "vanilla-framework": "3.7.0",
86
+ "vanilla-framework": "3.8.1",
87
87
  "wait-on": "5.3.0",
88
88
  "webpack": "5.74.0"
89
89
  },
@@ -107,7 +107,7 @@
107
107
  "peerDependencies": {
108
108
  "react": "^17.0.2 || ^18.0.0",
109
109
  "react-dom": "^17.0.2 || ^18.0.0",
110
- "vanilla-framework": "3.7.0"
110
+ "vanilla-framework": "3.8.1"
111
111
  },
112
112
  "scripts": {
113
113
  "build": "rm -rf dist && yarn build-local; yarn build-declaration",