@codecademy/gamut 67.6.4-alpha.1d4469.0 → 67.6.4-alpha.1d6b98.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.
Files changed (38) hide show
  1. package/dist/Anchor/index.d.ts +60 -12
  2. package/dist/Badge/index.d.ts +60 -12
  3. package/dist/Box/props.d.ts +60 -12
  4. package/dist/Button/shared/styles.d.ts +60 -12
  5. package/dist/Card/elements.d.ts +180 -36
  6. package/dist/ConnectedForm/ConnectedFormGroup.d.ts +2 -8
  7. package/dist/ConnectedForm/ConnectedFormGroup.js +1 -1
  8. package/dist/Form/elements/Form.d.ts +60 -12
  9. package/dist/Form/elements/FormGroupLabel.d.ts +2 -2
  10. package/dist/Form/elements/FormGroupLabel.js +3 -14
  11. package/dist/GridForm/GridFormInputGroup/GridFormRadioGroupInput/index.js +11 -19
  12. package/dist/GridForm/GridFormInputGroup/__fixtures__/renderers.d.ts +0 -4
  13. package/dist/GridForm/types.d.ts +2 -7
  14. package/dist/InternalFloatingCard/InternalFloatingCard.d.ts +30 -6
  15. package/dist/Layout/Column.d.ts +60 -12
  16. package/dist/Layout/LayoutGrid.d.ts +60 -12
  17. package/dist/List/elements.d.ts +120 -24
  18. package/dist/Menu/elements.d.ts +60 -12
  19. package/dist/Pagination/AnimatedPaginationButtons.d.ts +60 -12
  20. package/dist/Pagination/utils.d.ts +60 -12
  21. package/dist/Tabs/props.d.ts +60 -12
  22. package/dist/Tag/types.d.ts +60 -12
  23. package/dist/Tip/InfoTip/InfoTipButton.js +2 -5
  24. package/dist/Tip/InfoTip/elements.d.ts +12 -0
  25. package/dist/Tip/InfoTip/elements.js +9 -0
  26. package/dist/Tip/InfoTip/index.d.ts +1 -33
  27. package/dist/Tip/InfoTip/index.js +68 -46
  28. package/dist/Tip/__tests__/helpers.d.ts +26 -5
  29. package/dist/Tip/shared/FloatingTip.js +3 -3
  30. package/dist/Tip/shared/InlineTip.js +1 -4
  31. package/dist/Tip/shared/types.d.ts +1 -1
  32. package/dist/Tip/shared/utils.d.ts +0 -19
  33. package/dist/Tip/shared/utils.js +0 -104
  34. package/dist/Toggle/elements.d.ts +120 -24
  35. package/dist/Typography/Text.d.ts +60 -12
  36. package/package.json +7 -7
  37. package/dist/Tip/InfoTip/utils.d.ts +0 -13
  38. package/dist/Tip/InfoTip/utils.js +0 -47
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ export declare const ScreenreaderNavigableText: import("@emotion/styled").StyledComponent<(((Omit<{
3
+ theme?: import("@emotion/react").Theme | undefined;
4
+ as?: import("react").ElementType<any, keyof import("react").JSX.IntrinsicElements> | undefined;
5
+ } & import("../..").TextTruncateProps & Pick<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "slot" | "style" | "title" | "dir" | "children" | "className" | "aria-hidden" | "onAnimationStart" | "onDragStart" | "onDragEnd" | "onDrag" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "autoFocus" | "contentEditable" | "contextMenu" | "draggable" | "hidden" | "id" | "lang" | "nonce" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "content" | "datatype" | "inlist" | "prefix" | "property" | "rel" | "resource" | "rev" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-braillelabel" | "aria-brailleroledescription" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colindextext" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-description" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowindextext" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onResize" | "onResizeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDragCapture" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerLeave" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | keyof import("react").ClassAttributes<HTMLSpanElement>>, "ref"> | Omit<{
6
+ theme?: import("@emotion/react").Theme | undefined;
7
+ as?: import("react").ElementType<any, keyof import("react").JSX.IntrinsicElements> | undefined;
8
+ } & import("../..").TextNoTruncateProps & Pick<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "slot" | "style" | "title" | "dir" | "children" | "className" | "aria-hidden" | "onAnimationStart" | "onDragStart" | "onDragEnd" | "onDrag" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "autoFocus" | "contentEditable" | "contextMenu" | "draggable" | "hidden" | "id" | "lang" | "nonce" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "content" | "datatype" | "inlist" | "prefix" | "property" | "rel" | "resource" | "rev" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-braillelabel" | "aria-brailleroledescription" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colindextext" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-description" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowindextext" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onResize" | "onResizeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDragCapture" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerLeave" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | keyof import("react").ClassAttributes<HTMLSpanElement>>, "ref">) & import("react").RefAttributes<HTMLSpanElement>) & {
9
+ theme?: import("@emotion/react").Theme | undefined;
10
+ }) & {
11
+ theme?: import("@emotion/react").Theme | undefined;
12
+ }, {}, {}>;
@@ -0,0 +1,9 @@
1
+ import _styled from "@emotion/styled/base";
2
+ import { css } from '@codecademy/gamut-styles';
3
+ import { Text } from '../../Typography';
4
+ export const ScreenreaderNavigableText = /*#__PURE__*/_styled(Text, {
5
+ target: "e1rvjfdo0",
6
+ label: "ScreenreaderNavigableText"
7
+ })(css({
8
+ position: 'absolute'
9
+ }), process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9UaXAvSW5mb1RpcC9lbGVtZW50cy50c3giXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBS3lDIiwiZmlsZSI6Ii4uLy4uLy4uL3NyYy9UaXAvSW5mb1RpcC9lbGVtZW50cy50c3giLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgeyBjc3MgfSBmcm9tICdAY29kZWNhZGVteS9nYW11dC1zdHlsZXMnO1xuaW1wb3J0IHN0eWxlZCBmcm9tICdAZW1vdGlvbi9zdHlsZWQnO1xuXG5pbXBvcnQgeyBUZXh0IH0gZnJvbSAnLi4vLi4vVHlwb2dyYXBoeSc7XG5cbmV4cG9ydCBjb25zdCBTY3JlZW5yZWFkZXJOYXZpZ2FibGVUZXh0ID0gc3R5bGVkKFRleHQpKFxuICBjc3MoeyBwb3NpdGlvbjogJ2Fic29sdXRlJyB9KVxuKTtcbiJdfQ== */");
@@ -1,37 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import { TipBaseAlignment, TipBaseProps } from '../shared/types';
3
- type InfoTipPropsWithAriaLabel = TipBaseProps & {
3
+ export type InfoTipProps = TipBaseProps & {
4
4
  alignment?: TipBaseAlignment;
5
- /**
6
- * Accessible label for the InfoTip button. ariaLabel or ariaLabelledby should be provided for accessibility.
7
- */
8
- ariaLabel?: string;
9
- ariaLabelledby?: never;
10
- /**
11
- * Accessible role description for the InfoTip button. Useful for translation.
12
- * @default "More information button"
13
- */
14
- ariaRoleDescription?: string;
15
- emphasis?: 'low' | 'high';
16
- /**
17
- * Called when the info tip is clicked - the onClick function is called after the DOM updates and the tip is mounted.
18
- */
19
- onClick?: (arg0: {
20
- isTipHidden: boolean;
21
- }) => void;
22
- };
23
- type InfoTipPropsWithAriaLabelledby = TipBaseProps & {
24
- alignment?: TipBaseAlignment;
25
- ariaLabel?: never;
26
- /**
27
- * ID of an element that labels the InfoTip button.
28
- */
29
- ariaLabelledby?: string;
30
- /**
31
- * Accessible role description for the InfoTip button. Useful for translation.
32
- * @default "More information button"
33
- */
34
- ariaRoleDescription?: string;
35
5
  emphasis?: 'low' | 'high';
36
6
  /**
37
7
  * Called when the info tip is clicked - the onClick function is called after the DOM updates and the tip is mounted.
@@ -40,6 +10,4 @@ type InfoTipPropsWithAriaLabelledby = TipBaseProps & {
40
10
  isTipHidden: boolean;
41
11
  }) => void;
42
12
  };
43
- export type InfoTipProps = InfoTipPropsWithAriaLabel | InfoTipPropsWithAriaLabelledby;
44
13
  export declare const InfoTip: React.FC<InfoTipProps>;
45
- export {};
@@ -1,17 +1,19 @@
1
1
  import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
2
2
  import { getFocusableElements as getFocusableElementsUtil } from '../../utils/focus';
3
+ import { extractTextContent } from '../../utils/react';
3
4
  import { FloatingTip } from '../shared/FloatingTip';
4
5
  import { InlineTip } from '../shared/InlineTip';
5
6
  import { tipDefaultProps } from '../shared/types';
6
- import { isFloatingElementOpen } from '../shared/utils';
7
+ import { isElementVisible } from '../shared/utils';
8
+ import { ScreenreaderNavigableText } from './elements';
7
9
  import { InfoTipButton } from './InfoTipButton';
8
- import { jsx as _jsx } from "react/jsx-runtime";
10
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
11
+ const ARIA_HIDDEN_DELAY_MS = 1000;
12
+
13
+ // Match native dialogs with open attribute, and role-based dialogs that aren't aria-hidden
9
14
  const MODAL_SELECTOR = 'dialog[open],[role="dialog"]:not([aria-hidden="true"]),[role="alertdialog"]:not([aria-hidden="true"])';
10
15
  export const InfoTip = ({
11
16
  alignment = 'top-right',
12
- ariaLabel,
13
- ariaLabelledby,
14
- ariaRoleDescription = 'More information button',
15
17
  emphasis = 'low',
16
18
  info,
17
19
  onClick,
@@ -20,14 +22,25 @@ export const InfoTip = ({
20
22
  }) => {
21
23
  const isFloating = placement === 'floating';
22
24
  const [isTipHidden, setHideTip] = useState(true);
25
+ const [isAriaHidden, setIsAriaHidden] = useState(false);
26
+ const [shouldAnnounce, setShouldAnnounce] = useState(false);
23
27
  const [loaded, setLoaded] = useState(false);
24
28
  const wrapperRef = useRef(null);
25
29
  const buttonRef = useRef(null);
26
30
  const popoverContentNodeRef = useRef(null);
27
31
  const isInitialMount = useRef(true);
32
+ const ariaHiddenTimeoutRef = useRef(null);
33
+ const announceTimeoutRef = useRef(null);
28
34
  const getFocusableElements = useCallback(() => {
29
35
  return getFocusableElementsUtil(popoverContentNodeRef.current);
30
36
  }, []);
37
+ const clearAndSetTimeout = useCallback((timeoutRef, callback, delay) => {
38
+ clearTimeout(timeoutRef.current ?? undefined);
39
+ timeoutRef.current = setTimeout(() => {
40
+ callback();
41
+ timeoutRef.current = null;
42
+ }, delay);
43
+ }, []);
31
44
  const popoverContentRef = useCallback(node => {
32
45
  popoverContentNodeRef.current = node;
33
46
  if (node && !isTipHidden && isFloating) {
@@ -38,10 +51,24 @@ export const InfoTip = ({
38
51
  }, [onClick, isTipHidden, isFloating]);
39
52
  useEffect(() => {
40
53
  setLoaded(true);
54
+ const ariaHiddenTimeout = ariaHiddenTimeoutRef.current;
55
+ const announceTimeout = announceTimeoutRef.current;
56
+ return () => {
57
+ clearTimeout(ariaHiddenTimeout ?? undefined);
58
+ clearTimeout(announceTimeout ?? undefined);
59
+ };
41
60
  }, []);
42
61
  const setTipIsHidden = useCallback(nextTipState => {
43
62
  setHideTip(nextTipState);
44
- }, []);
63
+ if (!nextTipState && !isFloating) {
64
+ clearAndSetTimeout(ariaHiddenTimeoutRef, () => setIsAriaHidden(true), ARIA_HIDDEN_DELAY_MS);
65
+ } else if (nextTipState) {
66
+ if (isAriaHidden) setIsAriaHidden(false);
67
+ setShouldAnnounce(false);
68
+ clearTimeout(ariaHiddenTimeoutRef.current ?? undefined);
69
+ ariaHiddenTimeoutRef.current = null;
70
+ }
71
+ }, [isAriaHidden, isFloating, clearAndSetTimeout]);
45
72
  const handleOutsideClick = useCallback(e => {
46
73
  const wrapper = wrapperRef.current;
47
74
  const isOutside = wrapper && (!(e.target instanceof HTMLElement) || !wrapper.contains(e.target));
@@ -52,7 +79,10 @@ export const InfoTip = ({
52
79
  const clickHandler = useCallback(() => {
53
80
  const currentTipState = !isTipHidden;
54
81
  setTipIsHidden(currentTipState);
55
- }, [isTipHidden, setTipIsHidden]);
82
+ if (!currentTipState) {
83
+ clearAndSetTimeout(announceTimeoutRef, () => setShouldAnnounce(true), 0);
84
+ }
85
+ }, [isTipHidden, setTipIsHidden, clearAndSetTimeout]);
56
86
  useLayoutEffect(() => {
57
87
  if (isInitialMount.current) {
58
88
  isInitialMount.current = false;
@@ -78,14 +108,7 @@ export const InfoTip = ({
78
108
  const handleGlobalEscapeKey = e => {
79
109
  if (e.key !== 'Escape') return;
80
110
  const openModals = document.querySelectorAll(MODAL_SELECTOR);
81
- const hasUnrelatedModal = Array.from(openModals).some(modal => {
82
- // Only consider floating elements that are actually open
83
- if (!isFloatingElementOpen(modal)) {
84
- return false;
85
- }
86
- // Check if it's unrelated to this InfoTip
87
- return wrapperRef.current && !modal.contains(wrapperRef.current);
88
- });
111
+ const hasUnrelatedModal = Array.from(openModals).some(modal => isElementVisible(modal) && wrapperRef.current && !modal.contains(wrapperRef.current));
89
112
  if (hasUnrelatedModal) return;
90
113
  e.preventDefault();
91
114
  e.stopPropagation();
@@ -97,18 +120,7 @@ export const InfoTip = ({
97
120
  const handleTabKeyInPopover = event => {
98
121
  if (event.key !== 'Tab' || event.shiftKey) return;
99
122
  const focusableElements = getFocusableElements();
100
- const {
101
- activeElement
102
- } = document;
103
-
104
- // If no focusable elements and popover itself has focus, wrap to button
105
- if (focusableElements.length === 0) {
106
- if (activeElement === popoverContentNodeRef.current) {
107
- event.preventDefault();
108
- buttonRef.current?.focus();
109
- }
110
- return;
111
- }
123
+ if (focusableElements.length === 0) return;
112
124
  const lastElement = focusableElements[focusableElements.length - 1];
113
125
 
114
126
  // Only wrap forward: if on last element, wrap to button
@@ -129,35 +141,45 @@ export const InfoTip = ({
129
141
  };
130
142
  }
131
143
  return () => document.removeEventListener('keydown', handleGlobalEscapeKey, true);
132
- }, [isTipHidden, isFloating, getFocusableElements, setTipIsHidden]);
133
- useEffect(() => {
134
- if (isTipHidden) return;
135
- const timeoutId = setTimeout(() => {
136
- popoverContentNodeRef.current?.focus();
137
- }, 0);
138
- return () => clearTimeout(timeoutId);
139
- }, [isTipHidden]);
144
+ }, [isTipHidden, isFloating, setTipIsHidden, getFocusableElements]);
140
145
  const Tip = loaded && isFloating ? FloatingTip : InlineTip;
141
146
  const tipProps = useMemo(() => ({
142
147
  alignment,
143
148
  info,
144
149
  isTipHidden,
145
- contentRef: popoverContentRef,
146
150
  wrapperRef,
151
+ ...(isFloating && {
152
+ popoverContentRef
153
+ }),
147
154
  ...rest
148
- }), [alignment, info, isTipHidden, popoverContentRef, wrapperRef, rest]);
155
+ }), [alignment, info, isTipHidden, wrapperRef, isFloating, popoverContentRef, rest]);
156
+ const extractedTextContent = useMemo(() => extractTextContent(info), [info]);
157
+ const screenreaderInfo = shouldAnnounce && !isTipHidden ? extractedTextContent : '\xa0';
158
+ const screenreaderText = useMemo(() => /*#__PURE__*/_jsx(ScreenreaderNavigableText, {
159
+ "aria-hidden": isAriaHidden,
160
+ "aria-live": "assertive",
161
+ screenreader: true,
162
+ children: screenreaderInfo
163
+ }), [isAriaHidden, screenreaderInfo]);
164
+ const button = useMemo(() => /*#__PURE__*/_jsx(InfoTipButton, {
165
+ active: !isTipHidden,
166
+ "aria-expanded": !isTipHidden,
167
+ emphasis: emphasis,
168
+ ref: buttonRef,
169
+ onClick: clickHandler
170
+ }), [isTipHidden, emphasis, clickHandler]);
171
+
172
+ /*
173
+ * For floating placement, screenreader text comes before button to maintain
174
+ * correct DOM order despite Portal rendering. See GMT-64 for planned fix.
175
+ */
149
176
  return /*#__PURE__*/_jsx(Tip, {
150
177
  ...tipProps,
151
178
  type: "info",
152
- children: /*#__PURE__*/_jsx(InfoTipButton, {
153
- active: !isTipHidden,
154
- "aria-expanded": !isTipHidden,
155
- "aria-label": ariaLabel,
156
- "aria-labelledby": ariaLabelledby,
157
- "aria-roledescription": ariaRoleDescription,
158
- emphasis: emphasis,
159
- ref: buttonRef,
160
- onClick: clickHandler
179
+ children: isFloating && alignment.includes('top') ? /*#__PURE__*/_jsxs(_Fragment, {
180
+ children: [screenreaderText, button]
181
+ }) : /*#__PURE__*/_jsxs(_Fragment, {
182
+ children: [button, screenreaderText]
161
183
  })
162
184
  });
163
185
  };
@@ -2,9 +2,10 @@
2
2
  /// <reference types="testing-library__jest-dom" />
3
3
  import { setupRtl } from '@codecademy/gamut-tests';
4
4
  import { RefObject } from 'react';
5
- import { InfoTip } from '../InfoTip';
5
+ import { InfoTip, InfoTipProps } from '../InfoTip';
6
6
  import { TipPlacements } from '../shared/types';
7
7
  type InfoTipView = ReturnType<ReturnType<typeof setupRtl<typeof InfoTip>>>['view'];
8
+ type Placement = NonNullable<InfoTipProps['placement']>;
8
9
  type ViewParam = {
9
10
  view: InfoTipView;
10
11
  };
@@ -15,7 +16,7 @@ type InfoParam = {
15
16
  info: string;
16
17
  };
17
18
  type PlacementParam = {
18
- placement: TipPlacements;
19
+ placement: Placement;
19
20
  };
20
21
  export declare const createFocusOnClick: (ref: RefObject<HTMLDivElement>) => ({ isTipHidden }: {
21
22
  isTipHidden: boolean;
@@ -47,10 +48,13 @@ export declare const pressKey: (key: string) => Promise<void>;
47
48
  export declare const waitForLinkToHaveFocus: ({ view, linkText, }: ViewParam & LinkTextParam) => Promise<HTMLElement>;
48
49
  export declare const openTipAndWaitForLink: ({ view, linkText, }: ViewParam & LinkTextParam) => Promise<HTMLElement>;
49
50
  export declare const openTipTabToLinkAndWaitForFocus: (view: InfoTipView, linkText: string) => Promise<HTMLElement>;
50
- export declare const testFocusWrap: ({ view, direction, }: ViewParam & {
51
+ export declare const testShowTipOnClick: ({ view, info, placement, }: ViewParam & InfoParam & PlacementParam) => Promise<void>;
52
+ export declare const testEscapeKeyReturnsFocus: ({ view, info, placement, }: ViewParam & InfoParam & PlacementParam) => Promise<void>;
53
+ export declare const testFocusWrap: ({ view, containerRef, direction, }: ViewParam & {
54
+ containerRef: RefObject<HTMLDivElement>;
51
55
  direction: 'forward' | 'backward';
52
56
  }) => Promise<void>;
53
- export declare const testTabFromPopoverWithNoInteractiveElements: (view: InfoTipView) => Promise<void>;
57
+ export declare const getTipContent: (view: InfoTipView, text: string, useQuery?: boolean) => HTMLElement;
54
58
  export declare const testTabbingBetweenLinks: ({ view, firstLinkText, secondLinkText, placement, }: ViewParam & {
55
59
  firstLinkText: string;
56
60
  secondLinkText: string;
@@ -58,6 +62,7 @@ export declare const testTabbingBetweenLinks: ({ view, firstLinkText, secondLink
58
62
  }) => Promise<void>;
59
63
  export declare const setupLinkTestWithPlacement: (linkText: string, placement: TipPlacements, renderView: ReturnType<typeof setupRtl<typeof InfoTip>>) => {
60
64
  view: import("@testing-library/react").RenderResult;
65
+ containerRef: RefObject<HTMLDivElement>;
61
66
  info: import("react/jsx-runtime").JSX.Element;
62
67
  onClick: ({ isTipHidden }: {
63
68
  isTipHidden: boolean;
@@ -81,12 +86,28 @@ type ViewWithQueries = {
81
86
  getAllByText: (text: string) => HTMLElement[];
82
87
  getAllByLabelText: (text: string) => HTMLElement[];
83
88
  };
89
+ export declare const getVisibleTip: ({ text, placement, }: {
90
+ text: string;
91
+ placement?: "inline" | "floating" | undefined;
92
+ }) => HTMLElement | undefined;
93
+ export declare const expectTipToBeVisible: ({ text, placement, }: {
94
+ text: string;
95
+ placement?: "inline" | "floating" | undefined;
96
+ }) => void;
97
+ export declare const expectTipToBeClosed: ({ text, placement, }: {
98
+ text: string;
99
+ placement?: "inline" | "floating" | undefined;
100
+ }) => void;
84
101
  export declare const openInfoTipsWithKeyboard: ({ view, count, }: {
85
102
  view: ViewWithQueries;
86
103
  count: number;
87
104
  }) => Promise<void>;
88
105
  export declare const expectTipsVisible: (tips: {
89
106
  text: string;
107
+ placement?: 'inline' | 'floating';
108
+ }[]) => void;
109
+ export declare const expectTipsClosed: (tips: {
110
+ text: string;
111
+ placement?: 'inline' | 'floating';
90
112
  }[]) => void;
91
- export declare const expectTipsClosed: () => void;
92
113
  export {};
@@ -18,7 +18,7 @@ export const FloatingTip = ({
18
18
  loading,
19
19
  narrow,
20
20
  overline,
21
- contentRef,
21
+ popoverContentRef,
22
22
  truncateLines,
23
23
  type,
24
24
  username,
@@ -123,7 +123,7 @@ export const FloatingTip = ({
123
123
  width: inheritDims ? 'inherit' : undefined,
124
124
  onBlur: toolOnlyEventFunc,
125
125
  onFocus: toolOnlyEventFunc,
126
- onKeyDown: escapeKeyPressHandler,
126
+ onKeyDown: escapeKeyPressHandler ? e => escapeKeyPressHandler(e) : undefined,
127
127
  onMouseDown: e => e.preventDefault(),
128
128
  onMouseEnter: toolOnlyEventFunc,
129
129
  children: children
@@ -134,7 +134,7 @@ export const FloatingTip = ({
134
134
  horizontalOffset: offset,
135
135
  isOpen: isPopoverOpen,
136
136
  outline: true,
137
- popoverContainerRef: contentRef,
137
+ popoverContainerRef: popoverContentRef,
138
138
  skipFocusTrap: true,
139
139
  targetRef: ref,
140
140
  variant: "secondary",
@@ -17,7 +17,6 @@ export const InlineTip = ({
17
17
  loading,
18
18
  narrow,
19
19
  overline,
20
- contentRef,
21
20
  truncateLines,
22
21
  type,
23
22
  username,
@@ -43,7 +42,7 @@ export const InlineTip = ({
43
42
  height: inheritDims ? 'inherit' : undefined,
44
43
  ref: wrapperRef,
45
44
  width: inheritDims ? 'inherit' : undefined,
46
- onKeyDown: escapeKeyPressHandler,
45
+ onKeyDown: escapeKeyPressHandler ? e => escapeKeyPressHandler(e) : undefined,
47
46
  children: children
48
47
  });
49
48
  const tipBody = /*#__PURE__*/_jsx(InlineTipBodyWrapper, {
@@ -56,9 +55,7 @@ export const InlineTip = ({
56
55
  color: "currentColor",
57
56
  horizNarrow: narrow && isHorizontalCenter,
58
57
  id: id,
59
- ref: contentRef,
60
58
  role: type === 'tool' ? 'tooltip' : undefined,
61
- tabIndex: type === 'info' ? -1 : undefined,
62
59
  width: narrow && !isHorizontalCenter ? narrowWidth : 'max-content',
63
60
  zIndex: "auto",
64
61
  children: type === 'preview' ? /*#__PURE__*/_jsxs(_Fragment, {
@@ -46,7 +46,7 @@ export type TipPlacementComponentProps = Omit<TipNewBaseProps, 'placement' | 'em
46
46
  escapeKeyPressHandler?: (event: React.KeyboardEvent<HTMLDivElement>) => void;
47
47
  id?: string;
48
48
  isTipHidden?: boolean;
49
- contentRef?: React.RefObject<HTMLDivElement> | ((node: HTMLDivElement | null) => void);
49
+ popoverContentRef?: React.RefObject<HTMLDivElement> | ((node: HTMLDivElement | null) => void);
50
50
  type: 'info' | 'tool' | 'preview';
51
51
  wrapperRef?: React.RefObject<HTMLDivElement>;
52
52
  zIndex?: number;
@@ -6,22 +6,3 @@ export declare const escapeKeyPressHandler: (event: React.KeyboardEvent<HTMLDivE
6
6
  * Uses the modern checkVisibility API with a fallback for older browsers.
7
7
  */
8
8
  export declare const isElementVisible: (element: Element) => boolean;
9
- /**
10
- * Check if a floating element (modal, dialog, popover, overlay, etc.) is actually open and blocking.
11
- *
12
- * A floating element is considered "open" and blocking if:
13
- * 1. It's a <dialog> element with the open attribute (always blocking per HTML spec), OR
14
- * 2. It has role="alertdialog" (always blocking per ARIA spec), OR
15
- * 3. It has role="dialog" AND:
16
- * - It's not aria-hidden="true", AND
17
- * - It doesn't have aria-expanded="false" (for collapsible dialogs), AND
18
- * - It's actually visible (not just in DOM), AND
19
- * - It has aria-modal="true" (indicates blocking modal per ARIA spec)
20
- *
21
- * Non-blocking popovers and collapsible dialogs without aria-modal="true" are not considered
22
- * blocking and should not prevent InfoTip from closing.
23
- *
24
- * @param element - The DOM element to check
25
- * @returns `true` if the floating element is actually open and blocking, `false` otherwise
26
- */
27
- export declare const isFloatingElementOpen: (element: Element) => boolean;
@@ -15,108 +15,4 @@ export const escapeKeyPressHandler = event => {
15
15
  export const isElementVisible = element => {
16
16
  if (!(element instanceof HTMLElement)) return false;
17
17
  return element.checkVisibility?.() ?? true;
18
- };
19
-
20
- /**
21
- * Check if a floating element (modal, dialog, popover, overlay, etc.) is actually open and blocking.
22
- *
23
- * A floating element is considered "open" and blocking if:
24
- * 1. It's a <dialog> element with the open attribute (always blocking per HTML spec), OR
25
- * 2. It has role="alertdialog" (always blocking per ARIA spec), OR
26
- * 3. It has role="dialog" AND:
27
- * - It's not aria-hidden="true", AND
28
- * - It doesn't have aria-expanded="false" (for collapsible dialogs), AND
29
- * - It's actually visible (not just in DOM), AND
30
- * - It has aria-modal="true" (indicates blocking modal per ARIA spec)
31
- *
32
- * Non-blocking popovers and collapsible dialogs without aria-modal="true" are not considered
33
- * blocking and should not prevent InfoTip from closing.
34
- *
35
- * @param element - The DOM element to check
36
- * @returns `true` if the floating element is actually open and blocking, `false` otherwise
37
- */
38
- export const isFloatingElementOpen = element => {
39
- if (!isElementVisible(element)) return false;
40
-
41
- /**
42
- * Native <dialog> elements are always blocking when open.
43
- * Per HTML spec, dialog elements with the open attribute are modal.
44
- */
45
- if (element instanceof HTMLDialogElement) {
46
- return element.open === true;
47
- }
48
-
49
- /**
50
- * Elements with role="dialog" or role="alertdialog".
51
- * Per ARIA spec, role="alertdialog" is always modal (blocking).
52
- * role="dialog" requires aria-modal="true" to be blocking.
53
- */
54
- const role = element.getAttribute('role');
55
- if (role !== 'dialog' && role !== 'alertdialog') {
56
- return false;
57
- }
58
-
59
- /**
60
- * Cache attribute values to avoid multiple DOM reads.
61
- * Check aria-hidden first as it's a common exclusion case.
62
- */
63
- const ariaHidden = element.getAttribute('aria-hidden');
64
- if (ariaHidden === 'true') {
65
- return false;
66
- }
67
-
68
- /**
69
- * Check for collapsible dialogs (like help menus).
70
- * If aria-expanded exists and is false, the dialog is closed.
71
- * These dialogs stay in DOM but are collapsed when closed.
72
- */
73
- const ariaExpanded = element.getAttribute('aria-expanded');
74
- if (ariaExpanded === 'false') {
75
- return false;
76
- }
77
-
78
- /**
79
- * Per ARIA spec, role="alertdialog" is always modal (blocking).
80
- * At this point, we've already verified:
81
- * - The element is visible (not hidden via CSS)
82
- * - It's not aria-hidden="true"
83
- * - It's not aria-expanded="false"
84
- * So if it's an alertdialog, it's open and blocking.
85
- * Handle alertdialog here to avoid expensive DOM queries for dialog elements.
86
- */
87
- if (role === 'alertdialog') {
88
- return true;
89
- }
90
-
91
- /**
92
- * For role="dialog", check if any child button with aria-expanded indicates the dialog is closed.
93
- * Some dialogs use a toggle button pattern where the button's aria-expanded
94
- * reflects the dialog's state.
95
- * Only perform this expensive querySelector operation after all other checks pass.
96
- */
97
- const toggleButton = element.querySelector('button[aria-expanded], [role="button"][aria-expanded]');
98
- if (toggleButton && toggleButton.getAttribute('aria-expanded') === 'false') {
99
- return false;
100
- }
101
-
102
- /**
103
- * For role="dialog", check aria-modal attribute.
104
- * aria-modal="true" indicates a blocking modal (Modal, Dialog).
105
- * aria-modal="false" or absence indicates non-blocking.
106
- */
107
- const ariaModal = element.getAttribute('aria-modal');
108
- if (ariaModal === 'true') {
109
- return true;
110
- }
111
- if (ariaModal === 'false') {
112
- // Explicitly non-modal, should not block
113
- return false;
114
- }
115
-
116
- /**
117
- * Elements with role="dialog" but without aria-modal="true" are non-blocking.
118
- * These include collapsible dialogs (help menus) and popovers (Popover, InfoTip, Tooltip)
119
- * that use role="dialog". They should not prevent InfoTip from closing.
120
- */
121
- return false;
122
18
  };