@codecademy/gamut 67.6.5-alpha.9b8a7f.0 → 67.6.5-alpha.c4325a.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/BarChart/BarChartProvider.d.ts +19 -0
- package/dist/BarChart/BarChartProvider.js +31 -0
- package/dist/BarChart/BarRow/elements.d.ts +713 -0
- package/dist/BarChart/BarRow/elements.js +89 -0
- package/dist/BarChart/BarRow/index.d.ts +26 -0
- package/dist/BarChart/BarRow/index.js +254 -0
- package/dist/BarChart/GENERIC_EXAMPLE.d.ts +14 -0
- package/dist/BarChart/GENERIC_EXAMPLE.js +333 -0
- package/dist/BarChart/index.d.ts +4 -0
- package/dist/BarChart/index.js +156 -0
- package/dist/BarChart/layout/GridLines.d.ts +7 -0
- package/dist/BarChart/layout/GridLines.js +78 -0
- package/dist/BarChart/layout/ScaleChartHeader.d.ts +10 -0
- package/dist/BarChart/layout/ScaleChartHeader.js +89 -0
- package/dist/BarChart/layout/VerticalSpacer.d.ts +6 -0
- package/dist/BarChart/layout/VerticalSpacer.js +56 -0
- package/dist/BarChart/shared/elements.d.ts +7 -0
- package/dist/BarChart/shared/elements.js +12 -0
- package/dist/BarChart/shared/styles.d.ts +4 -0
- package/dist/BarChart/shared/styles.js +4 -0
- package/dist/BarChart/shared/translations.d.ts +17 -0
- package/dist/BarChart/shared/translations.js +16 -0
- package/dist/BarChart/shared/types.d.ts +88 -0
- package/dist/BarChart/shared/types.js +1 -0
- package/dist/BarChart/utils/hooks.d.ts +93 -0
- package/dist/BarChart/utils/hooks.js +301 -0
- package/dist/BarChart/utils/index.d.ts +86 -0
- package/dist/BarChart/utils/index.js +165 -0
- package/dist/ConnectedForm/ConnectedFormGroup.d.ts +2 -8
- package/dist/ConnectedForm/ConnectedFormGroup.js +1 -1
- package/dist/ConnectedForm/ConnectedInputs/ConnectedCheckbox.js +0 -2
- package/dist/ConnectedForm/utils.d.ts +1 -1
- package/dist/Form/SelectDropdown/styles.d.ts +1 -1
- package/dist/Form/elements/Form.d.ts +1 -1
- package/dist/Form/elements/FormGroupLabel.d.ts +2 -2
- package/dist/Form/elements/FormGroupLabel.js +3 -10
- package/dist/Form/inputs/Checkbox.d.ts +0 -7
- package/dist/Form/inputs/Checkbox.js +11 -27
- package/dist/Form/inputs/Radio.d.ts +5 -9
- package/dist/Form/inputs/Radio.js +10 -13
- package/dist/Form/inputs/Select.js +6 -5
- package/dist/Form/styles/Radio-styles.d.ts +3 -0
- package/dist/Form/styles/Radio-styles.js +6 -0
- package/dist/Form/styles/shared-system-props.d.ts +0 -7
- package/dist/Form/styles/shared-system-props.js +0 -11
- package/dist/GridForm/GridFormInputGroup/GridFormRadioGroupInput/index.js +0 -2
- package/dist/GridForm/GridFormInputGroup/__fixtures__/renderers.d.ts +0 -4
- package/dist/GridForm/types.d.ts +2 -7
- package/dist/List/elements.d.ts +1 -1
- package/dist/Tip/InfoTip/InfoTipButton.js +2 -5
- package/dist/Tip/InfoTip/elements.d.ts +12 -0
- package/dist/Tip/InfoTip/elements.js +9 -0
- package/dist/Tip/InfoTip/index.d.ts +2 -27
- package/dist/Tip/InfoTip/index.js +67 -50
- package/dist/Tip/__tests__/helpers.d.ts +26 -5
- package/dist/Tip/shared/FloatingTip.js +3 -3
- package/dist/Tip/shared/InlineTip.js +1 -4
- package/dist/Tip/shared/types.d.ts +1 -1
- package/dist/Tip/shared/utils.d.ts +0 -19
- package/dist/Tip/shared/utils.js +0 -104
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +2 -2
- package/dist/Form/__tests__/testUtils.d.ts +0 -22
- package/dist/Tip/InfoTip/type-utils.d.ts +0 -35
- package/dist/Tip/InfoTip/type-utils.js +0 -72
|
@@ -1,22 +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 {
|
|
7
|
+
import { isElementVisible } from '../shared/utils';
|
|
8
|
+
import { ScreenreaderNavigableText } from './elements';
|
|
7
9
|
import { InfoTipButton } from './InfoTipButton';
|
|
10
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
const ARIA_HIDDEN_DELAY_MS = 1000;
|
|
8
12
|
|
|
9
|
-
|
|
10
|
-
* Base props shared by all InfoTip variants.
|
|
11
|
-
* Contains all common props except the aria-* specific props.
|
|
12
|
-
*/
|
|
13
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
// Match native dialogs with open attribute, and role-based dialogs that aren't aria-hidden
|
|
14
14
|
const MODAL_SELECTOR = 'dialog[open],[role="dialog"]:not([aria-hidden="true"]),[role="alertdialog"]:not([aria-hidden="true"])';
|
|
15
15
|
export const InfoTip = ({
|
|
16
16
|
alignment = 'top-right',
|
|
17
|
-
ariaLabel,
|
|
18
|
-
ariaLabelledby,
|
|
19
|
-
ariaRoleDescription = 'More information button',
|
|
20
17
|
emphasis = 'low',
|
|
21
18
|
info,
|
|
22
19
|
onClick,
|
|
@@ -25,14 +22,25 @@ export const InfoTip = ({
|
|
|
25
22
|
}) => {
|
|
26
23
|
const isFloating = placement === 'floating';
|
|
27
24
|
const [isTipHidden, setHideTip] = useState(true);
|
|
25
|
+
const [isAriaHidden, setIsAriaHidden] = useState(false);
|
|
26
|
+
const [shouldAnnounce, setShouldAnnounce] = useState(false);
|
|
28
27
|
const [loaded, setLoaded] = useState(false);
|
|
29
28
|
const wrapperRef = useRef(null);
|
|
30
29
|
const buttonRef = useRef(null);
|
|
31
30
|
const popoverContentNodeRef = useRef(null);
|
|
32
31
|
const isInitialMount = useRef(true);
|
|
32
|
+
const ariaHiddenTimeoutRef = useRef(null);
|
|
33
|
+
const announceTimeoutRef = useRef(null);
|
|
33
34
|
const getFocusableElements = useCallback(() => {
|
|
34
35
|
return getFocusableElementsUtil(popoverContentNodeRef.current);
|
|
35
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
|
+
}, []);
|
|
36
44
|
const popoverContentRef = useCallback(node => {
|
|
37
45
|
popoverContentNodeRef.current = node;
|
|
38
46
|
if (node && !isTipHidden && isFloating) {
|
|
@@ -43,10 +51,24 @@ export const InfoTip = ({
|
|
|
43
51
|
}, [onClick, isTipHidden, isFloating]);
|
|
44
52
|
useEffect(() => {
|
|
45
53
|
setLoaded(true);
|
|
54
|
+
const ariaHiddenTimeout = ariaHiddenTimeoutRef.current;
|
|
55
|
+
const announceTimeout = announceTimeoutRef.current;
|
|
56
|
+
return () => {
|
|
57
|
+
clearTimeout(ariaHiddenTimeout ?? undefined);
|
|
58
|
+
clearTimeout(announceTimeout ?? undefined);
|
|
59
|
+
};
|
|
46
60
|
}, []);
|
|
47
61
|
const setTipIsHidden = useCallback(nextTipState => {
|
|
48
62
|
setHideTip(nextTipState);
|
|
49
|
-
|
|
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]);
|
|
50
72
|
const handleOutsideClick = useCallback(e => {
|
|
51
73
|
const wrapper = wrapperRef.current;
|
|
52
74
|
const isOutside = wrapper && (!(e.target instanceof HTMLElement) || !wrapper.contains(e.target));
|
|
@@ -57,7 +79,10 @@ export const InfoTip = ({
|
|
|
57
79
|
const clickHandler = useCallback(() => {
|
|
58
80
|
const currentTipState = !isTipHidden;
|
|
59
81
|
setTipIsHidden(currentTipState);
|
|
60
|
-
|
|
82
|
+
if (!currentTipState) {
|
|
83
|
+
clearAndSetTimeout(announceTimeoutRef, () => setShouldAnnounce(true), 0);
|
|
84
|
+
}
|
|
85
|
+
}, [isTipHidden, setTipIsHidden, clearAndSetTimeout]);
|
|
61
86
|
useLayoutEffect(() => {
|
|
62
87
|
if (isInitialMount.current) {
|
|
63
88
|
isInitialMount.current = false;
|
|
@@ -83,14 +108,7 @@ export const InfoTip = ({
|
|
|
83
108
|
const handleGlobalEscapeKey = e => {
|
|
84
109
|
if (e.key !== 'Escape') return;
|
|
85
110
|
const openModals = document.querySelectorAll(MODAL_SELECTOR);
|
|
86
|
-
const hasUnrelatedModal = Array.from(openModals).some(modal =>
|
|
87
|
-
// Only consider floating elements that are actually open
|
|
88
|
-
if (!isFloatingElementOpen(modal)) {
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
// Check if it's unrelated to this InfoTip
|
|
92
|
-
return wrapperRef.current && !modal.contains(wrapperRef.current);
|
|
93
|
-
});
|
|
111
|
+
const hasUnrelatedModal = Array.from(openModals).some(modal => isElementVisible(modal) && wrapperRef.current && !modal.contains(wrapperRef.current));
|
|
94
112
|
if (hasUnrelatedModal) return;
|
|
95
113
|
e.preventDefault();
|
|
96
114
|
e.stopPropagation();
|
|
@@ -102,18 +120,7 @@ export const InfoTip = ({
|
|
|
102
120
|
const handleTabKeyInPopover = event => {
|
|
103
121
|
if (event.key !== 'Tab' || event.shiftKey) return;
|
|
104
122
|
const focusableElements = getFocusableElements();
|
|
105
|
-
|
|
106
|
-
activeElement
|
|
107
|
-
} = document;
|
|
108
|
-
|
|
109
|
-
// If no focusable elements and popover itself has focus, wrap to button
|
|
110
|
-
if (focusableElements.length === 0) {
|
|
111
|
-
if (activeElement === popoverContentNodeRef.current) {
|
|
112
|
-
event.preventDefault();
|
|
113
|
-
buttonRef.current?.focus();
|
|
114
|
-
}
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
123
|
+
if (focusableElements.length === 0) return;
|
|
117
124
|
const lastElement = focusableElements[focusableElements.length - 1];
|
|
118
125
|
|
|
119
126
|
// Only wrap forward: if on last element, wrap to button
|
|
@@ -134,35 +141,45 @@ export const InfoTip = ({
|
|
|
134
141
|
};
|
|
135
142
|
}
|
|
136
143
|
return () => document.removeEventListener('keydown', handleGlobalEscapeKey, true);
|
|
137
|
-
}, [isTipHidden, isFloating,
|
|
138
|
-
useEffect(() => {
|
|
139
|
-
if (isTipHidden) return;
|
|
140
|
-
const timeoutId = setTimeout(() => {
|
|
141
|
-
popoverContentNodeRef.current?.focus();
|
|
142
|
-
}, 0);
|
|
143
|
-
return () => clearTimeout(timeoutId);
|
|
144
|
-
}, [isTipHidden]);
|
|
144
|
+
}, [isTipHidden, isFloating, setTipIsHidden, getFocusableElements]);
|
|
145
145
|
const Tip = loaded && isFloating ? FloatingTip : InlineTip;
|
|
146
146
|
const tipProps = useMemo(() => ({
|
|
147
147
|
alignment,
|
|
148
148
|
info,
|
|
149
149
|
isTipHidden,
|
|
150
|
-
contentRef: popoverContentRef,
|
|
151
150
|
wrapperRef,
|
|
151
|
+
...(isFloating && {
|
|
152
|
+
popoverContentRef
|
|
153
|
+
}),
|
|
152
154
|
...rest
|
|
153
|
-
}), [alignment, info, isTipHidden,
|
|
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
|
+
*/
|
|
154
176
|
return /*#__PURE__*/_jsx(Tip, {
|
|
155
177
|
...tipProps,
|
|
156
178
|
type: "info",
|
|
157
|
-
children: /*#__PURE__*/
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
"aria-labelledby": ariaLabelledby,
|
|
162
|
-
"aria-roledescription": ariaRoleDescription,
|
|
163
|
-
emphasis: emphasis,
|
|
164
|
-
ref: buttonRef,
|
|
165
|
-
onClick: clickHandler
|
|
179
|
+
children: isFloating && alignment.includes('top') ? /*#__PURE__*/_jsxs(_Fragment, {
|
|
180
|
+
children: [screenreaderText, button]
|
|
181
|
+
}) : /*#__PURE__*/_jsxs(_Fragment, {
|
|
182
|
+
children: [button, screenreaderText]
|
|
166
183
|
})
|
|
167
184
|
});
|
|
168
185
|
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { setupRtl } from '@codecademy/gamut-tests';
|
|
2
2
|
import { RefObject } from 'react';
|
|
3
|
-
import { InfoTip } from '../InfoTip';
|
|
3
|
+
import { InfoTip, InfoTipProps } from '../InfoTip';
|
|
4
4
|
import { TipPlacements } from '../shared/types';
|
|
5
5
|
type InfoTipView = ReturnType<ReturnType<typeof setupRtl<typeof InfoTip>>>['view'];
|
|
6
|
+
type Placement = NonNullable<InfoTipProps['placement']>;
|
|
6
7
|
type ViewParam = {
|
|
7
8
|
view: InfoTipView;
|
|
8
9
|
};
|
|
@@ -13,7 +14,7 @@ type InfoParam = {
|
|
|
13
14
|
info: string;
|
|
14
15
|
};
|
|
15
16
|
type PlacementParam = {
|
|
16
|
-
placement:
|
|
17
|
+
placement: Placement;
|
|
17
18
|
};
|
|
18
19
|
export declare const createFocusOnClick: (ref: RefObject<HTMLDivElement>) => ({ isTipHidden }: {
|
|
19
20
|
isTipHidden: boolean;
|
|
@@ -45,10 +46,13 @@ export declare const pressKey: (key: string) => Promise<void>;
|
|
|
45
46
|
export declare const waitForLinkToHaveFocus: ({ view, linkText, }: ViewParam & LinkTextParam) => Promise<HTMLElement>;
|
|
46
47
|
export declare const openTipAndWaitForLink: ({ view, linkText, }: ViewParam & LinkTextParam) => Promise<HTMLElement>;
|
|
47
48
|
export declare const openTipTabToLinkAndWaitForFocus: (view: InfoTipView, linkText: string) => Promise<HTMLElement>;
|
|
48
|
-
export declare const
|
|
49
|
+
export declare const testShowTipOnClick: ({ view, info, placement, }: ViewParam & InfoParam & PlacementParam) => Promise<void>;
|
|
50
|
+
export declare const testEscapeKeyReturnsFocus: ({ view, info, placement, }: ViewParam & InfoParam & PlacementParam) => Promise<void>;
|
|
51
|
+
export declare const testFocusWrap: ({ view, containerRef, direction, }: ViewParam & {
|
|
52
|
+
containerRef: RefObject<HTMLDivElement>;
|
|
49
53
|
direction: 'forward' | 'backward';
|
|
50
54
|
}) => Promise<void>;
|
|
51
|
-
export declare const
|
|
55
|
+
export declare const getTipContent: (view: InfoTipView, text: string, useQuery?: boolean) => HTMLElement;
|
|
52
56
|
export declare const testTabbingBetweenLinks: ({ view, firstLinkText, secondLinkText, placement, }: ViewParam & {
|
|
53
57
|
firstLinkText: string;
|
|
54
58
|
secondLinkText: string;
|
|
@@ -56,6 +60,7 @@ export declare const testTabbingBetweenLinks: ({ view, firstLinkText, secondLink
|
|
|
56
60
|
}) => Promise<void>;
|
|
57
61
|
export declare const setupLinkTestWithPlacement: (linkText: string, placement: TipPlacements, renderView: ReturnType<typeof setupRtl<typeof InfoTip>>) => {
|
|
58
62
|
view: import("@testing-library/react").RenderResult;
|
|
63
|
+
containerRef: RefObject<HTMLDivElement>;
|
|
59
64
|
info: import("react/jsx-runtime").JSX.Element;
|
|
60
65
|
onClick: ({ isTipHidden }: {
|
|
61
66
|
isTipHidden: boolean;
|
|
@@ -79,12 +84,28 @@ type ViewWithQueries = {
|
|
|
79
84
|
getAllByText: (text: string) => HTMLElement[];
|
|
80
85
|
getAllByLabelText: (text: string) => HTMLElement[];
|
|
81
86
|
};
|
|
87
|
+
export declare const getVisibleTip: ({ text, placement, }: {
|
|
88
|
+
text: string;
|
|
89
|
+
placement?: "inline" | "floating" | undefined;
|
|
90
|
+
}) => HTMLElement | undefined;
|
|
91
|
+
export declare const expectTipToBeVisible: ({ text, placement, }: {
|
|
92
|
+
text: string;
|
|
93
|
+
placement?: "inline" | "floating" | undefined;
|
|
94
|
+
}) => void;
|
|
95
|
+
export declare const expectTipToBeClosed: ({ text, placement, }: {
|
|
96
|
+
text: string;
|
|
97
|
+
placement?: "inline" | "floating" | undefined;
|
|
98
|
+
}) => void;
|
|
82
99
|
export declare const openInfoTipsWithKeyboard: ({ view, count, }: {
|
|
83
100
|
view: ViewWithQueries;
|
|
84
101
|
count: number;
|
|
85
102
|
}) => Promise<void>;
|
|
86
103
|
export declare const expectTipsVisible: (tips: {
|
|
87
104
|
text: string;
|
|
105
|
+
placement?: 'inline' | 'floating';
|
|
106
|
+
}[]) => void;
|
|
107
|
+
export declare const expectTipsClosed: (tips: {
|
|
108
|
+
text: string;
|
|
109
|
+
placement?: 'inline' | 'floating';
|
|
88
110
|
}[]) => void;
|
|
89
|
-
export declare const expectTipsClosed: () => void;
|
|
90
111
|
export {};
|
|
@@ -18,7 +18,7 @@ export const FloatingTip = ({
|
|
|
18
18
|
loading,
|
|
19
19
|
narrow,
|
|
20
20
|
overline,
|
|
21
|
-
|
|
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:
|
|
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
|
-
|
|
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;
|
package/dist/Tip/shared/utils.js
CHANGED
|
@@ -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
|
};
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codecademy/gamut",
|
|
3
3
|
"description": "Styleguide & Component library for Codecademy",
|
|
4
|
-
"version": "67.6.5-alpha.
|
|
4
|
+
"version": "67.6.5-alpha.c4325a.0",
|
|
5
5
|
"author": "Codecademy Engineering <dev@codecademy.com>",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@codecademy/gamut-icons": "9.54.1",
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"dist/**/[A-Z]**/[A-Z]*.js",
|
|
57
57
|
"dist/**/[A-Z]**/index.js"
|
|
58
58
|
],
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "26a58aa3c4e83bf2de37f2d47afd9418c68fddb7"
|
|
60
60
|
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { RenderResult } from '@testing-library/react';
|
|
2
|
-
/**
|
|
3
|
-
* Creates and appends an external label element to the test container.
|
|
4
|
-
* This is useful for testing ariaLabelledby functionality where an InfoTip
|
|
5
|
-
* references an external label element.
|
|
6
|
-
*
|
|
7
|
-
* @param view - The render result from testing-library
|
|
8
|
-
* @param id - The ID of the external label element (used in ariaLabelledby)
|
|
9
|
-
* @param text - The text content of the external label
|
|
10
|
-
* @returns The created span element
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* const { view } = renderView({
|
|
15
|
-
* infotip: { info, ariaLabelledby: 'external-label-id' },
|
|
16
|
-
* });
|
|
17
|
-
*
|
|
18
|
-
* createExternalLabel(view, 'external-label-id', 'External Label');
|
|
19
|
-
* view.getByRole('button', { name: 'External Label' });
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export declare const createExternalLabel: (view: RenderResult, id: string, text: string) => HTMLSpanElement;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { InfoTipBaseProps, InfoTipProps } from './index';
|
|
2
|
-
type InfoTipAriaLabel = InfoTipBaseProps & {
|
|
3
|
-
ariaLabel?: string;
|
|
4
|
-
ariaLabelledby?: never;
|
|
5
|
-
};
|
|
6
|
-
type InfoTipAriaLabelledby = InfoTipBaseProps & {
|
|
7
|
-
ariaLabel?: never;
|
|
8
|
-
ariaLabelledby?: string;
|
|
9
|
-
};
|
|
10
|
-
type InfoTipPropsAriaWithFallback = InfoTipBaseProps & {
|
|
11
|
-
ariaLabel?: never;
|
|
12
|
-
ariaLabelledby?: never;
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* InfoTip props that allow both ariaLabel and ariaLabelledby to be optional.
|
|
16
|
-
* Used in components that automatically provide ariaLabelledby when neither is provided.
|
|
17
|
-
*/
|
|
18
|
-
export type InfoTipSubComponentProps = InfoTipAriaLabel | InfoTipAriaLabelledby | InfoTipPropsAriaWithFallback;
|
|
19
|
-
export declare const createInfoTipProps: (props: InfoTipSubComponentProps, fallbackAriaLabelledby?: string) => {
|
|
20
|
-
infotipProps: InfoTipProps;
|
|
21
|
-
shouldLabelInfoTip: boolean;
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Hook to handle infotip props and accessibility labeling.
|
|
25
|
-
* Extracts the common pattern used by Radio, Checkbox, and FormGroupLabel components.
|
|
26
|
-
*
|
|
27
|
-
* @param infotip - Optional infotip subcomponent props
|
|
28
|
-
* @returns Object containing infotipProps, labelId, and shouldLabelInfoTip flag
|
|
29
|
-
*/
|
|
30
|
-
export declare const useInfotipProps: (infotip?: InfoTipSubComponentProps) => {
|
|
31
|
-
infotipProps: InfoTipProps | undefined;
|
|
32
|
-
labelId: string;
|
|
33
|
-
shouldLabelInfoTip: boolean;
|
|
34
|
-
};
|
|
35
|
-
export {};
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { useId } from 'react';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* InfoTip props that allow both ariaLabel and ariaLabelledby to be optional.
|
|
5
|
-
* Used in components that automatically provide ariaLabelledby when neither is provided.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export const createInfoTipProps = (props, fallbackAriaLabelledby) => {
|
|
9
|
-
const {
|
|
10
|
-
ariaLabel,
|
|
11
|
-
ariaLabelledby,
|
|
12
|
-
...rest
|
|
13
|
-
} = props;
|
|
14
|
-
const hasAriaLabel = ariaLabel !== undefined;
|
|
15
|
-
const hasAriaLabelledby = ariaLabelledby !== undefined;
|
|
16
|
-
if (hasAriaLabel) {
|
|
17
|
-
return {
|
|
18
|
-
infotipProps: {
|
|
19
|
-
...rest,
|
|
20
|
-
ariaLabel
|
|
21
|
-
},
|
|
22
|
-
shouldLabelInfoTip: false
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
if (hasAriaLabelledby) {
|
|
26
|
-
return {
|
|
27
|
-
infotipProps: {
|
|
28
|
-
...rest,
|
|
29
|
-
ariaLabelledby
|
|
30
|
-
},
|
|
31
|
-
shouldLabelInfoTip: false
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
if (fallbackAriaLabelledby) {
|
|
35
|
-
return {
|
|
36
|
-
infotipProps: {
|
|
37
|
-
...rest,
|
|
38
|
-
ariaLabelledby: fallbackAriaLabelledby
|
|
39
|
-
},
|
|
40
|
-
shouldLabelInfoTip: true
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
return {
|
|
44
|
-
infotipProps: {
|
|
45
|
-
...rest
|
|
46
|
-
},
|
|
47
|
-
shouldLabelInfoTip: false
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Hook to handle infotip props and accessibility labeling.
|
|
53
|
-
* Extracts the common pattern used by Radio, Checkbox, and FormGroupLabel components.
|
|
54
|
-
*
|
|
55
|
-
* @param infotip - Optional infotip subcomponent props
|
|
56
|
-
* @returns Object containing infotipProps, labelId, and shouldLabelInfoTip flag
|
|
57
|
-
*/
|
|
58
|
-
export const useInfotipProps = infotip => {
|
|
59
|
-
const labelId = useId();
|
|
60
|
-
const {
|
|
61
|
-
infotipProps,
|
|
62
|
-
shouldLabelInfoTip
|
|
63
|
-
} = infotip ? createInfoTipProps(infotip, labelId) : {
|
|
64
|
-
infotipProps: undefined,
|
|
65
|
-
shouldLabelInfoTip: false
|
|
66
|
-
};
|
|
67
|
-
return {
|
|
68
|
-
infotipProps,
|
|
69
|
-
labelId,
|
|
70
|
-
shouldLabelInfoTip
|
|
71
|
-
};
|
|
72
|
-
};
|