@pingux/astro 2.1.2-alpha.1 → 2.1.2-alpha.2

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.
@@ -12,6 +12,8 @@ exports["default"] = void 0;
12
12
  var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
13
13
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/objectWithoutProperties"));
14
14
  var _react = _interopRequireWildcard(require("react"));
15
+ var _reactAria = require("react-aria");
16
+ var _interactions = require("@react-aria/interactions");
15
17
  var _propTypes = _interopRequireDefault(require("prop-types"));
16
18
  var _uuid = require("uuid");
17
19
  var _ = require("../..");
@@ -39,15 +41,26 @@ var HelpHint = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
39
41
  iconButtonProps = props.iconButtonProps,
40
42
  others = (0, _objectWithoutProperties2["default"])(props, _excluded);
41
43
  var tooltipId = (0, _uuid.v4)();
44
+ var buttonRef = (0, _react.useRef)();
45
+ var _useFocusRing = (0, _reactAria.useFocusRing)(),
46
+ focusProps = _useFocusRing.focusProps,
47
+ isFocusVisible = _useFocusRing.isFocusVisible;
48
+ var _useHover = (0, _interactions.useHover)({}),
49
+ hoverProps = _useHover.hoverProps,
50
+ isHovered = _useHover.isHovered;
51
+ var isTooltipOpen = isFocusVisible || isHovered;
42
52
  return (0, _react2.jsx)(_TooltipTrigger["default"], (0, _extends2["default"])({
43
53
  ref: ref,
44
54
  direction: "top"
45
- }, others, tooltipProps), (0, _react2.jsx)(_IconButton["default"], (0, _extends2["default"])({
55
+ }, others, {
56
+ isOpen: isTooltipOpen
57
+ }, tooltipProps), (0, _react2.jsx)(_IconButton["default"], (0, _extends2["default"])({
58
+ ref: buttonRef,
46
59
  variant: "hintButton",
47
60
  "aria-label": "label help hint",
48
61
  "data-testid": "help-hint__button",
49
- "aria-describedby": tooltipId
50
- }, iconButtonProps), (0, _react2.jsx)(_.Icon, {
62
+ "aria-describedby": isTooltipOpen ? tooltipId : null
63
+ }, iconButtonProps, hoverProps, focusProps), (0, _react2.jsx)(_.Icon, {
51
64
  icon: HelpIcon
52
65
  })), (0, _react2.jsx)(_TooltipTrigger.Tooltip, (0, _extends2["default"])({}, tooltipProps, {
53
66
  role: "tooltip",
@@ -31,7 +31,10 @@ test('shows tooltip on hover', function () {
31
31
  expect(_testWrapper.screen.queryByText(tooltipValue)).not.toBeInTheDocument();
32
32
  _testWrapper.fireEvent.mouseMove(helpHintButton);
33
33
  _testWrapper.fireEvent.mouseEnter(helpHintButton);
34
- expect(_testWrapper.screen.getByText(tooltipValue)).toBeInTheDocument();
34
+ var tooltip = _testWrapper.screen.getByRole('tooltip');
35
+ var tooltipId = tooltip.getAttribute('id');
36
+ expect(tooltip).toBeInTheDocument();
37
+ expect(helpHintButton).toHaveAttribute('aria-describedby', tooltipId);
35
38
  });
36
39
  test('shows tooltip on focus', function () {
37
40
  getComponent();
@@ -39,7 +42,10 @@ test('shows tooltip on focus', function () {
39
42
  expect(_testWrapper.screen.queryByText(tooltipValue)).not.toBeInTheDocument();
40
43
  _userEvent["default"].tab();
41
44
  expect(helpHintButton).toHaveFocus();
42
- expect(_testWrapper.screen.queryByText(tooltipValue)).toBeInTheDocument();
45
+ var tooltip = _testWrapper.screen.getByRole('tooltip');
46
+ var tooltipId = tooltip.getAttribute('id');
47
+ expect(tooltip).toBeInTheDocument();
48
+ expect(helpHintButton).toHaveAttribute('aria-describedby', tooltipId);
43
49
  });
44
50
  test('applies tooltipProps', function () {
45
51
  getComponent({
@@ -1,7 +1,9 @@
1
1
  import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
3
3
  var _excluded = ["children", "tooltipProps", "iconButtonProps"];
4
- import React, { forwardRef } from 'react';
4
+ import React, { forwardRef, useRef } from 'react';
5
+ import { useFocusRing } from 'react-aria';
6
+ import { useHover } from '@react-aria/interactions';
5
7
  import PropTypes from 'prop-types';
6
8
  import { v4 as uuid } from 'uuid';
7
9
  import { Icon } from '../..';
@@ -26,15 +28,26 @@ var HelpHint = /*#__PURE__*/forwardRef(function (props, ref) {
26
28
  iconButtonProps = props.iconButtonProps,
27
29
  others = _objectWithoutProperties(props, _excluded);
28
30
  var tooltipId = uuid();
31
+ var buttonRef = useRef();
32
+ var _useFocusRing = useFocusRing(),
33
+ focusProps = _useFocusRing.focusProps,
34
+ isFocusVisible = _useFocusRing.isFocusVisible;
35
+ var _useHover = useHover({}),
36
+ hoverProps = _useHover.hoverProps,
37
+ isHovered = _useHover.isHovered;
38
+ var isTooltipOpen = isFocusVisible || isHovered;
29
39
  return ___EmotionJSX(TooltipTrigger, _extends({
30
40
  ref: ref,
31
41
  direction: "top"
32
- }, others, tooltipProps), ___EmotionJSX(IconButton, _extends({
42
+ }, others, {
43
+ isOpen: isTooltipOpen
44
+ }, tooltipProps), ___EmotionJSX(IconButton, _extends({
45
+ ref: buttonRef,
33
46
  variant: "hintButton",
34
47
  "aria-label": "label help hint",
35
48
  "data-testid": "help-hint__button",
36
- "aria-describedby": tooltipId
37
- }, iconButtonProps), ___EmotionJSX(Icon, {
49
+ "aria-describedby": isTooltipOpen ? tooltipId : null
50
+ }, iconButtonProps, hoverProps, focusProps), ___EmotionJSX(Icon, {
38
51
  icon: HelpIcon
39
52
  })), ___EmotionJSX(Tooltip, _extends({}, tooltipProps, {
40
53
  role: "tooltip",
@@ -28,7 +28,10 @@ test('shows tooltip on hover', function () {
28
28
  expect(screen.queryByText(tooltipValue)).not.toBeInTheDocument();
29
29
  fireEvent.mouseMove(helpHintButton);
30
30
  fireEvent.mouseEnter(helpHintButton);
31
- expect(screen.getByText(tooltipValue)).toBeInTheDocument();
31
+ var tooltip = screen.getByRole('tooltip');
32
+ var tooltipId = tooltip.getAttribute('id');
33
+ expect(tooltip).toBeInTheDocument();
34
+ expect(helpHintButton).toHaveAttribute('aria-describedby', tooltipId);
32
35
  });
33
36
  test('shows tooltip on focus', function () {
34
37
  getComponent();
@@ -36,7 +39,10 @@ test('shows tooltip on focus', function () {
36
39
  expect(screen.queryByText(tooltipValue)).not.toBeInTheDocument();
37
40
  userEvent.tab();
38
41
  expect(helpHintButton).toHaveFocus();
39
- expect(screen.queryByText(tooltipValue)).toBeInTheDocument();
42
+ var tooltip = screen.getByRole('tooltip');
43
+ var tooltipId = tooltip.getAttribute('id');
44
+ expect(tooltip).toBeInTheDocument();
45
+ expect(helpHintButton).toHaveAttribute('aria-describedby', tooltipId);
40
46
  });
41
47
  test('applies tooltipProps', function () {
42
48
  getComponent({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pingux/astro",
3
- "version": "2.1.2-alpha.1",
3
+ "version": "2.1.2-alpha.2",
4
4
  "description": "PingUX themeable React component library",
5
5
  "repository": {
6
6
  "type": "git",