@ultraviolet/ui 1.14.0 → 1.15.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.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as react from 'react';
2
- import react__default, { ReactNode, ComponentProps, ButtonHTMLAttributes, AriaRole, MouseEventHandler, JSX, MouseEvent, InputHTMLAttributes, HTMLAttributeAnchorTarget, AnchorHTMLAttributes, ReactElement, Ref, RefObject, CSSProperties, ChangeEventHandler, FocusEventHandler, ForwardRefExoticComponent, ForwardedRef, HTMLAttributes, ElementType, KeyboardEventHandler, TextareaHTMLAttributes } from 'react';
2
+ import react__default, { ReactNode, ComponentProps, ButtonHTMLAttributes, AriaRole, MouseEventHandler, JSX, MouseEvent, InputHTMLAttributes, HTMLAttributeAnchorTarget, AnchorHTMLAttributes, ReactElement, Ref, RefObject, KeyboardEventHandler, HTMLAttributes, CSSProperties, ChangeEventHandler, FocusEventHandler, ForwardRefExoticComponent, ForwardedRef, ElementType, TextareaHTMLAttributes } from 'react';
3
3
  import * as _emotion_react_jsx_runtime from '@emotion/react/jsx-runtime';
4
4
  import * as _emotion_styled from '@emotion/styled';
5
5
  import * as _emotion_react from '@emotion/react';
@@ -1758,6 +1758,8 @@ type TooltipProps$1 = {
1758
1758
  'data-testid'?: string;
1759
1759
  hasArrow?: boolean;
1760
1760
  onClose?: () => void;
1761
+ onKeyDown?: KeyboardEventHandler;
1762
+ 'aria-haspopup'?: HTMLAttributes<HTMLDivElement>['aria-haspopup'];
1761
1763
  };
1762
1764
  declare const Popup: react.ForwardRefExoticComponent<TooltipProps$1 & react.RefAttributes<HTMLDivElement>>;
1763
1765
 
@@ -1774,7 +1776,7 @@ type PopoverProps = {
1774
1776
  sentiment?: SentimentType;
1775
1777
  visible?: boolean;
1776
1778
  size?: keyof typeof SIZES_WIDTH;
1777
- onClose: () => void;
1779
+ onClose?: () => void;
1778
1780
  className?: string;
1779
1781
  'data-testid'?: string;
1780
1782
  } & Pick<ComponentProps<typeof Popup>, 'placement'>;
@@ -1,5 +1,5 @@
1
1
  import _styled from '@emotion/styled/base';
2
- import { useRef, useCallback, useEffect } from 'react';
2
+ import { useRef, useState, useEffect, useCallback } from 'react';
3
3
  import { Button } from '../Button/index.js';
4
4
  import { Stack } from '../Stack/index.js';
5
5
  import { Text } from '../Text/index.js';
@@ -62,6 +62,10 @@ const ContentWrapper = _ref5 => {
62
62
  children,
63
63
  sentiment
64
64
  } = _ref5;
65
+ const buttonRef = useRef(null);
66
+ useEffect(() => {
67
+ buttonRef.current?.focus();
68
+ }, []);
65
69
  return jsxs(Stack, {
66
70
  gap: 1,
67
71
  children: [jsxs(Stack, {
@@ -78,7 +82,8 @@ const ContentWrapper = _ref5 => {
78
82
  onClick: onClose,
79
83
  size: "small",
80
84
  icon: "close",
81
- "aria-label": "close"
85
+ "aria-label": "close",
86
+ ref: buttonRef
82
87
  })]
83
88
  }), typeof children === 'string' ? jsx(Text, {
84
89
  variant: "bodySmall",
@@ -106,9 +111,16 @@ const Popover = _ref6 => {
106
111
  'data-testid': dataTestId
107
112
  } = _ref6;
108
113
  const ref = useRef(null);
114
+ const innerRef = useRef(null);
115
+ const [localVisible, setLocalVisible] = useState(visible);
116
+
117
+ // We change local value if visible prop changes
118
+ useEffect(() => {
119
+ setLocalVisible(visible);
120
+ }, [visible]);
109
121
  const handleClickOutside = useCallback(event => {
110
122
  if (ref.current && !ref.current.contains(event.target)) {
111
- onClose();
123
+ onClose?.();
112
124
  }
113
125
  }, [onClose]);
114
126
  useEffect(() => {
@@ -117,12 +129,28 @@ const Popover = _ref6 => {
117
129
  document.removeEventListener('click', handleClickOutside, true);
118
130
  };
119
131
  }, [handleClickOutside]);
132
+
133
+ // When space key is pressed we show the popover
134
+ const onKeyDownSpace = useCallback(event => {
135
+ if (event.code === 'Space') {
136
+ event.preventDefault();
137
+ event.stopPropagation();
138
+ setLocalVisible(true);
139
+ }
140
+ }, []);
141
+
142
+ // When we close we hide the popover and focus the disclosure element
143
+ const localOnClose = useCallback(() => {
144
+ setLocalVisible(false);
145
+ onClose?.();
146
+ innerRef.current?.focus();
147
+ }, [onClose]);
120
148
  return jsx(StyledPopup, {
121
- visible: visible,
149
+ visible: localVisible,
122
150
  placement: placement,
123
151
  text: jsx(ContentWrapper, {
124
152
  title: title,
125
- onClose: onClose,
153
+ onClose: localOnClose,
126
154
  sentiment: sentiment,
127
155
  children: content
128
156
  }),
@@ -132,6 +160,9 @@ const Popover = _ref6 => {
132
160
  size: size,
133
161
  role: "dialog",
134
162
  ref: ref,
163
+ innerRef: innerRef,
164
+ onClose: localOnClose,
165
+ onKeyDown: onKeyDownSpace,
135
166
  children: children
136
167
  });
137
168
  };
@@ -1,7 +1,20 @@
1
+ import _styled from '@emotion/styled/base';
1
2
  import { forwardRef } from 'react';
2
3
  import { jsx } from '@emotion/react/jsx-runtime';
3
4
  import { Popup } from '../../internalComponents/Popup/index.js';
4
5
 
6
+ function _EMOTION_STRINGIFIED_CSS_ERROR__() { return "You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."; }
7
+ const StyledPopup = /*#__PURE__*/_styled(Popup, {
8
+ target: "e1h4zly10"
9
+ })(process.env.NODE_ENV === "production" ? {
10
+ name: "je8g23",
11
+ styles: "pointer-events:none"
12
+ } : {
13
+ name: "je8g23",
14
+ styles: "pointer-events:none",
15
+ toString: _EMOTION_STRINGIFIED_CSS_ERROR__
16
+ });
17
+
5
18
  /**
6
19
  * Tooltip component is used to display additional information on hover or focus.
7
20
  * It is used to explain the purpose of the element it is attached to.
@@ -20,7 +33,7 @@ const Tooltip = /*#__PURE__*/forwardRef((_ref, tooltipRef) => {
20
33
  role = 'tooltip',
21
34
  'data-testid': dataTestId
22
35
  } = _ref;
23
- return jsx(Popup, {
36
+ return jsx(StyledPopup, {
24
37
  id: id,
25
38
  ref: tooltipRef,
26
39
  role: role,
@@ -118,7 +118,9 @@ const Popup = /*#__PURE__*/forwardRef((_ref13, tooltipRef) => {
118
118
  role = 'tooltip',
119
119
  'data-testid': dataTestId,
120
120
  hasArrow = true,
121
- onClose
121
+ onClose,
122
+ onKeyDown,
123
+ 'aria-haspopup': ariaHasPopup
122
124
  } = _ref13;
123
125
  const childrenRef = useRef(null);
124
126
  useImperativeHandle(innerRef, () => childrenRef.current);
@@ -235,7 +237,7 @@ const Popup = /*#__PURE__*/forwardRef((_ref13, tooltipRef) => {
235
237
  onPointerEvent(visible)();
236
238
  }
237
239
  }, [isControlled, onPointerEvent, visible]);
238
- const onKeyDown = useCallback(event => {
240
+ const onLocalKeyDown = useCallback(event => {
239
241
  if (event.code === 'Escape') {
240
242
  unmountTooltip();
241
243
  }
@@ -290,11 +292,15 @@ const Popup = /*#__PURE__*/forwardRef((_ref13, tooltipRef) => {
290
292
  onPointerLeave: !isControlled ? onPointerEvent(false) : noop,
291
293
  ref: childrenRef,
292
294
  tabIndex: 0,
293
- onKeyDown: onKeyDown,
295
+ onKeyDown: event => {
296
+ onKeyDown?.(event);
297
+ onLocalKeyDown(event);
298
+ },
294
299
  "data-container-full-width": containerFullWidth,
300
+ "aria-haspopup": ariaHasPopup,
295
301
  children: children
296
302
  });
297
- }, [children, containerFullWidth, generatedId, isControlled, onKeyDown, onPointerEvent]);
303
+ }, [ariaHasPopup, children, containerFullWidth, generatedId, isControlled, onKeyDown, onLocalKeyDown, onPointerEvent]);
298
304
  if (!text) {
299
305
  if (typeof children === 'function') return null;
300
306
  return jsx(Fragment, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultraviolet/ui",
3
- "version": "1.14.0",
3
+ "version": "1.15.0",
4
4
  "description": "Ultraviolet UI",
5
5
  "homepage": "https://github.com/scaleway/ultraviolet#readme",
6
6
  "repository": {