carbon-react 144.2.2 → 144.4.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/esm/components/drawer/drawer.component.d.ts +3 -1
- package/esm/components/drawer/drawer.component.js +10 -3
- package/esm/components/drawer/drawer.style.d.ts +1 -1
- package/esm/components/drawer/drawer.style.js +1 -1
- package/esm/components/note/note.component.d.ts +1 -1
- package/esm/components/note/note.component.js +10 -2
- package/esm/components/note/note.style.d.ts +2 -2
- package/esm/components/note/note.style.js +7 -4
- package/esm/components/select/__internal__/select-list/select-list.component.js +1 -1
- package/esm/components/select/multi-select/multi-select.component.js +46 -104
- package/lib/components/drawer/drawer.component.d.ts +3 -1
- package/lib/components/drawer/drawer.component.js +10 -3
- package/lib/components/drawer/drawer.style.d.ts +1 -1
- package/lib/components/drawer/drawer.style.js +1 -1
- package/lib/components/note/note.component.d.ts +1 -1
- package/lib/components/note/note.component.js +9 -1
- package/lib/components/note/note.style.d.ts +2 -2
- package/lib/components/note/note.style.js +7 -4
- package/lib/components/select/__internal__/select-list/select-list.component.js +1 -1
- package/lib/components/select/multi-select/multi-select.component.js +46 -104
- package/package.json +1 -1
|
@@ -6,6 +6,8 @@ export interface DrawerProps extends Omit<TagProps, "data-component"> {
|
|
|
6
6
|
animationDuration?: string;
|
|
7
7
|
/** Specify an aria-label for the Drawer component */
|
|
8
8
|
"aria-label"?: string;
|
|
9
|
+
/** Specify an aria-label for the Drawer sidebar */
|
|
10
|
+
sidebarAriaLabel?: string;
|
|
9
11
|
/** Sets color of sidebar's background */
|
|
10
12
|
backgroundColor?: string;
|
|
11
13
|
children: React.ReactNode;
|
|
@@ -30,6 +32,6 @@ export interface DrawerProps extends Omit<TagProps, "data-component"> {
|
|
|
30
32
|
/** Makes the footer of the drawer sticky. Footer prop must also be set. */
|
|
31
33
|
stickyFooter?: boolean;
|
|
32
34
|
}
|
|
33
|
-
export declare const Drawer: ({ "aria-label": ariaLabel, "data-element": dataElement, "data-role": dataRole, defaultExpanded, expanded, onChange, children, expandedWidth, sidebar, animationDuration, backgroundColor, title, footer, showControls, height, stickyHeader, stickyFooter, }: DrawerProps) => React.JSX.Element;
|
|
35
|
+
export declare const Drawer: ({ "aria-label": ariaLabel, sidebarAriaLabel, "data-element": dataElement, "data-role": dataRole, defaultExpanded, expanded, onChange, children, expandedWidth, sidebar, animationDuration, backgroundColor, title, footer, showControls, height, stickyHeader, stickyFooter, }: DrawerProps) => React.JSX.Element;
|
|
34
36
|
export { DrawerSidebarContext };
|
|
35
37
|
export default Drawer;
|
|
@@ -9,6 +9,7 @@ import StickyFooter from "../../__internal__/sticky-footer";
|
|
|
9
9
|
import DrawerSidebarContext from "./__internal__/drawer-sidebar.context";
|
|
10
10
|
export const Drawer = ({
|
|
11
11
|
"aria-label": ariaLabel,
|
|
12
|
+
sidebarAriaLabel,
|
|
12
13
|
"data-element": dataElement,
|
|
13
14
|
"data-role": dataRole = "drawer",
|
|
14
15
|
defaultExpanded = true,
|
|
@@ -91,6 +92,7 @@ export const Drawer = ({
|
|
|
91
92
|
}, [toggleAnimation, isExpanded, onChange]);
|
|
92
93
|
const guid = useRef(createGuid());
|
|
93
94
|
const sidebarId = `DrawerSidebar_${guid.current}`;
|
|
95
|
+
const titleId = `DrawerTitle_${guid.current}`;
|
|
94
96
|
const getClassNames = useCallback(() => {
|
|
95
97
|
const classes = [isExpanded ? "open" : "closed"];
|
|
96
98
|
if (isOpening) {
|
|
@@ -128,15 +130,20 @@ export const Drawer = ({
|
|
|
128
130
|
ref: drawerSidebarContentRef,
|
|
129
131
|
backgroundColor: backgroundColor,
|
|
130
132
|
"data-element": "drawer-content",
|
|
131
|
-
"data-role": "drawer-content"
|
|
133
|
+
"data-role": "drawer-content",
|
|
134
|
+
"aria-label": sidebarAriaLabel,
|
|
135
|
+
"aria-labelledby": title ? titleId : undefined
|
|
132
136
|
}, stickyHeader && /*#__PURE__*/React.createElement(StyledSidebarHeader, {
|
|
133
137
|
"data-role": "drawer-sidebar-header",
|
|
134
138
|
isExpanded: isExpanded
|
|
135
|
-
}, title && /*#__PURE__*/React.createElement(StyledSidebarTitle,
|
|
139
|
+
}, title && /*#__PURE__*/React.createElement(StyledSidebarTitle, {
|
|
140
|
+
id: titleId
|
|
141
|
+
}, title), getControls()), !stickyHeader && /*#__PURE__*/React.createElement(React.Fragment, null, title && /*#__PURE__*/React.createElement(StyledSidebarTitle, {
|
|
142
|
+
id: titleId
|
|
143
|
+
}, title), getControls()), /*#__PURE__*/React.createElement(StyledDrawerSidebar, {
|
|
136
144
|
hasControls: !!showControls,
|
|
137
145
|
id: sidebarId,
|
|
138
146
|
isExpanded: isExpanded,
|
|
139
|
-
role: "navigation",
|
|
140
147
|
overflowY: isExpanded ? "auto" : undefined,
|
|
141
148
|
scrollVariant: "light",
|
|
142
149
|
ref: scrollableContentRef
|
|
@@ -14,7 +14,7 @@ interface StyledDrawerContentProps {
|
|
|
14
14
|
backgroundColor?: string;
|
|
15
15
|
expandedWidth: string;
|
|
16
16
|
}
|
|
17
|
-
declare const StyledDrawerContent: import("styled-components").StyledComponent<"
|
|
17
|
+
declare const StyledDrawerContent: import("styled-components").StyledComponent<"aside", any, StyledDrawerContentProps, never>;
|
|
18
18
|
interface StyledSidebarToggleButtonProps {
|
|
19
19
|
animationDuration?: string;
|
|
20
20
|
isExpanded?: boolean;
|
|
@@ -89,7 +89,7 @@ const buttonClose = () => keyframes`
|
|
|
89
89
|
80% {float: right;}
|
|
90
90
|
100% {float: left;}
|
|
91
91
|
`;
|
|
92
|
-
const StyledDrawerContent = styled.
|
|
92
|
+
const StyledDrawerContent = styled.aside`
|
|
93
93
|
display: flex;
|
|
94
94
|
flex-direction: column;
|
|
95
95
|
min-width: ${defaultExpandedWidth};
|
|
@@ -20,7 +20,7 @@ export interface NoteProps extends MarginProps {
|
|
|
20
20
|
timeStamp: string;
|
|
21
21
|
};
|
|
22
22
|
/** Adds a Title to the Note */
|
|
23
|
-
title?:
|
|
23
|
+
title?: React.ReactNode;
|
|
24
24
|
/** Set a percentage-based width for the whole Note component, relative to its parent. */
|
|
25
25
|
width?: number;
|
|
26
26
|
}
|
|
@@ -3,12 +3,13 @@ import React from "react";
|
|
|
3
3
|
import PropTypes from "prop-types";
|
|
4
4
|
import { Editor } from "draft-js";
|
|
5
5
|
import invariant from "invariant";
|
|
6
|
-
import { StyledNote, StyledNoteContent, StyledNoteMain, StyledInlineControl,
|
|
6
|
+
import { StyledNote, StyledNoteContent, StyledNoteMain, StyledInlineControl, StyledTitleWrapper, StyledFooter, StyledFooterContent } from "./note.style";
|
|
7
7
|
import StatusIcon from "./__internal__/status-icon";
|
|
8
8
|
import { ActionPopover } from "../action-popover";
|
|
9
9
|
import { getDecoratedValue } from "../text-editor/__internal__/utils";
|
|
10
10
|
import EditorContext from "../text-editor/__internal__/editor.context";
|
|
11
11
|
import LinkPreview from "../link-preview";
|
|
12
|
+
import Typography from "../typography";
|
|
12
13
|
function hasExpectedDisplayName(child, displayName) {
|
|
13
14
|
return child.type.displayName === displayName;
|
|
14
15
|
}
|
|
@@ -50,7 +51,14 @@ export const Note = ({
|
|
|
50
51
|
width: width
|
|
51
52
|
}, rest, {
|
|
52
53
|
"data-component": "note"
|
|
53
|
-
}), /*#__PURE__*/React.createElement(StyledNoteMain, null, /*#__PURE__*/React.createElement(StyledNoteContent, null, title &&
|
|
54
|
+
}), /*#__PURE__*/React.createElement(StyledNoteMain, null, /*#__PURE__*/React.createElement(StyledNoteContent, null, title && (typeof title === "string" ? /*#__PURE__*/React.createElement(Typography, {
|
|
55
|
+
"data-role": "note-title",
|
|
56
|
+
fontWeight: "700",
|
|
57
|
+
fontSize: "16px",
|
|
58
|
+
lineHeight: "21px",
|
|
59
|
+
paddingBottom: "16px",
|
|
60
|
+
variant: "h2"
|
|
61
|
+
}, title) : /*#__PURE__*/React.createElement(StyledTitleWrapper, null, title)), /*#__PURE__*/React.createElement(Editor, {
|
|
54
62
|
readOnly: true,
|
|
55
63
|
editorState: getDecoratedValue(noteContent),
|
|
56
64
|
onChange: /* istanbul ignore next */() => {}
|
|
@@ -3,7 +3,7 @@ declare const StyledNoteContent: import("styled-components").StyledComponent<"di
|
|
|
3
3
|
}, never>;
|
|
4
4
|
declare const StyledNoteMain: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
5
5
|
declare const StyledInlineControl: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
6
|
-
declare const
|
|
6
|
+
declare const StyledTitleWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
7
7
|
declare const StyledFooterContent: import("styled-components").StyledComponent<"div", any, {
|
|
8
8
|
hasName: boolean;
|
|
9
9
|
}, never>;
|
|
@@ -11,4 +11,4 @@ declare const StyledFooter: import("styled-components").StyledComponent<"div", a
|
|
|
11
11
|
declare const StyledNote: import("styled-components").StyledComponent<"div", any, {
|
|
12
12
|
width: number;
|
|
13
13
|
}, never>;
|
|
14
|
-
export { StyledNote, StyledNoteContent, StyledNoteMain, StyledInlineControl,
|
|
14
|
+
export { StyledNote, StyledNoteContent, StyledNoteMain, StyledInlineControl, StyledTitleWrapper, StyledFooter, StyledFooterContent, };
|
|
@@ -2,6 +2,7 @@ import styled, { css } from "styled-components";
|
|
|
2
2
|
import { margin } from "styled-system";
|
|
3
3
|
import baseTheme from "../../style/themes/base";
|
|
4
4
|
import { StyledLinkPreview } from "../link-preview/link-preview.style";
|
|
5
|
+
import { VARIANT_TYPES } from "../typography/typography.component";
|
|
5
6
|
const StyledNoteContent = styled.div`
|
|
6
7
|
position: relative;
|
|
7
8
|
width: 100%;
|
|
@@ -11,13 +12,11 @@ const StyledNoteContent = styled.div`
|
|
|
11
12
|
}) => css`
|
|
12
13
|
div.DraftEditor-root {
|
|
13
14
|
min-height: inherit;
|
|
14
|
-
height: 100%;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
div.DraftEditor-editorContainer,
|
|
18
18
|
div.public-DraftEditor-content {
|
|
19
19
|
min-height: inherit;
|
|
20
|
-
height: 100%;
|
|
21
20
|
background-color: var(--colorsUtilityYang100);
|
|
22
21
|
line-height: 21px;
|
|
23
22
|
}
|
|
@@ -40,11 +39,15 @@ const StyledInlineControl = styled.div`
|
|
|
40
39
|
display: inline-block;
|
|
41
40
|
min-width: fit-content;
|
|
42
41
|
`;
|
|
43
|
-
const
|
|
42
|
+
const StyledTitleWrapper = styled.div`
|
|
43
|
+
${VARIANT_TYPES.map(variant => `
|
|
44
|
+
${variant}{
|
|
44
45
|
font-weight: 700;
|
|
45
46
|
font-size: 16px;
|
|
46
47
|
line-height: 21px;
|
|
47
48
|
padding-bottom: 16px;
|
|
49
|
+
}
|
|
50
|
+
`)}
|
|
48
51
|
`;
|
|
49
52
|
const StyledFooterContent = styled.div`
|
|
50
53
|
line-height: 21px;
|
|
@@ -128,4 +131,4 @@ const StyledNote = styled.div`
|
|
|
128
131
|
StyledNote.defaultProps = {
|
|
129
132
|
theme: baseTheme
|
|
130
133
|
};
|
|
131
|
-
export { StyledNote, StyledNoteContent, StyledNoteMain, StyledInlineControl,
|
|
134
|
+
export { StyledNote, StyledNoteContent, StyledNoteMain, StyledInlineControl, StyledTitleWrapper, StyledFooter, StyledFooterContent };
|
|
@@ -380,7 +380,7 @@ const SelectList = /*#__PURE__*/React.forwardRef(({
|
|
|
380
380
|
}
|
|
381
381
|
}), ...(flipEnabled ? [flip({
|
|
382
382
|
fallbackStrategy: "initialPlacement"
|
|
383
|
-
})] : [])], [listWidth, flipEnabled]);
|
|
383
|
+
})] : /* istanbul ignore next: covered by Playwright tests for reliable positioning in a real browser */[])], [listWidth, flipEnabled]);
|
|
384
384
|
const loader = isLoading ? /*#__PURE__*/React.createElement(StyledSelectLoaderContainer, {
|
|
385
385
|
key: "loader"
|
|
386
386
|
}, /*#__PURE__*/React.createElement(Loader, null)) : undefined;
|
|
@@ -63,18 +63,16 @@ const MultiSelect = /*#__PURE__*/React.forwardRef(({
|
|
|
63
63
|
const accessibilityLabelId = useRef(guid());
|
|
64
64
|
const containerRef = useRef(null);
|
|
65
65
|
const listboxRef = useRef(null);
|
|
66
|
-
const isInputFocused = useRef(false);
|
|
67
66
|
const isClickTriggeredBySelect = useRef(false);
|
|
68
67
|
const isMouseDownReported = useRef(false);
|
|
69
68
|
const isMouseDownOnInput = useRef(false);
|
|
70
|
-
const isOpenedByFocus =
|
|
69
|
+
const [isOpenedByFocus, setIsOpenedByFocus] = useState(false);
|
|
71
70
|
const isControlled = useRef(value !== undefined);
|
|
72
71
|
const [textboxRef, setTextboxRef] = useState();
|
|
73
|
-
const [
|
|
72
|
+
const [open, setOpen] = useState(false);
|
|
74
73
|
const [textValue, setTextValue] = useState("");
|
|
75
74
|
const [selectedValue, setSelectedValue] = useState(value || defaultValue || []);
|
|
76
75
|
const [highlightedValue, setHighlightedValue] = useState("");
|
|
77
|
-
const [filterText, setFilterText] = useState("");
|
|
78
76
|
const [placeholderOverride, setPlaceholderOverride] = useState();
|
|
79
77
|
const inputId = useRef(id || guid());
|
|
80
78
|
const {
|
|
@@ -83,21 +81,12 @@ const MultiSelect = /*#__PURE__*/React.forwardRef(({
|
|
|
83
81
|
id: inputId.current,
|
|
84
82
|
label
|
|
85
83
|
});
|
|
86
|
-
const focusTimer = useRef(null);
|
|
87
84
|
const actualValue = isControlled.current ? value : selectedValue;
|
|
88
85
|
const componentIsUncontrolled = !isControlled || !onChange && defaultValue;
|
|
89
86
|
if (!deprecateUncontrolledWarnTriggered && componentIsUncontrolled) {
|
|
90
87
|
deprecateUncontrolledWarnTriggered = true;
|
|
91
88
|
Logger.deprecate("Uncontrolled behaviour in `Multi Select` is deprecated and support will soon be removed. Please make sure all your inputs are controlled.");
|
|
92
89
|
}
|
|
93
|
-
const setOpen = useCallback(() => {
|
|
94
|
-
setOpenState(isAlreadyOpen => {
|
|
95
|
-
if (!isAlreadyOpen && onOpen) {
|
|
96
|
-
onOpen();
|
|
97
|
-
}
|
|
98
|
-
return true;
|
|
99
|
-
});
|
|
100
|
-
}, [onOpen]);
|
|
101
90
|
const createCustomEvent = useCallback((newValue, selectionConfirmed) => {
|
|
102
91
|
const customEvent = {
|
|
103
92
|
target: {
|
|
@@ -144,10 +133,12 @@ const MultiSelect = /*#__PURE__*/React.forwardRef(({
|
|
|
144
133
|
if (match) {
|
|
145
134
|
setHighlightedValue(match.props.value);
|
|
146
135
|
}
|
|
147
|
-
setFilterText(newValue);
|
|
148
136
|
setTextValue(newValue);
|
|
149
|
-
|
|
150
|
-
|
|
137
|
+
if (!open) {
|
|
138
|
+
onOpen?.();
|
|
139
|
+
}
|
|
140
|
+
setOpen(true);
|
|
141
|
+
}, [children, open, onOpen]);
|
|
151
142
|
const removeSelectedValue = useCallback(index => {
|
|
152
143
|
isClickTriggeredBySelect.current = true;
|
|
153
144
|
updateValue(previousValue => {
|
|
@@ -164,21 +155,21 @@ const MultiSelect = /*#__PURE__*/React.forwardRef(({
|
|
|
164
155
|
key
|
|
165
156
|
} = event;
|
|
166
157
|
const isDeleteKey = key === "Backspace" || key === "Delete";
|
|
167
|
-
|
|
168
|
-
onKeyDown(event);
|
|
169
|
-
}
|
|
158
|
+
onKeyDown?.(event);
|
|
170
159
|
if (readOnly) {
|
|
171
160
|
return;
|
|
172
161
|
}
|
|
173
162
|
if (!event.defaultPrevented && isNavigationKey(key)) {
|
|
174
163
|
event.preventDefault();
|
|
175
|
-
|
|
164
|
+
if (!open) {
|
|
165
|
+
onOpen?.();
|
|
166
|
+
}
|
|
167
|
+
setOpen(true);
|
|
176
168
|
}
|
|
177
|
-
if (isDeleteKey &&
|
|
169
|
+
if (isDeleteKey && textValue === "") {
|
|
178
170
|
removeSelectedValue(-1);
|
|
179
171
|
}
|
|
180
|
-
|
|
181
|
-
}, [onKeyDown, readOnly, filterText, textValue, setOpen, removeSelectedValue]);
|
|
172
|
+
}, [onKeyDown, readOnly, textValue, open, onOpen, removeSelectedValue]);
|
|
182
173
|
const accessibilityLabel = useMemo(() => {
|
|
183
174
|
return actualValue && actualValue.length ? React.Children.map(children, child => {
|
|
184
175
|
return /*#__PURE__*/React.isValidElement(child) && actualValue.includes(child.props.value) ? child.props.text : false;
|
|
@@ -188,19 +179,18 @@ const MultiSelect = /*#__PURE__*/React.forwardRef(({
|
|
|
188
179
|
}, [children, actualValue]);
|
|
189
180
|
const handleGlobalClick = useCallback(event => {
|
|
190
181
|
isMouseDownReported.current = false;
|
|
191
|
-
if (!
|
|
182
|
+
if (!open) {
|
|
192
183
|
return;
|
|
193
184
|
}
|
|
194
185
|
const notInContainer = containerRef.current && !containerRef.current.contains(event.target);
|
|
195
186
|
const notInList = listboxRef.current && !listboxRef.current.contains(event.target);
|
|
196
187
|
if (notInContainer && notInList && !isClickTriggeredBySelect.current) {
|
|
197
188
|
setTextValue("");
|
|
198
|
-
setFilterText("");
|
|
199
189
|
setHighlightedValue("");
|
|
200
|
-
|
|
190
|
+
setOpen(false);
|
|
201
191
|
}
|
|
202
192
|
isClickTriggeredBySelect.current = false;
|
|
203
|
-
}, [
|
|
193
|
+
}, [open]);
|
|
204
194
|
const mapValuesToPills = useMemo(() => {
|
|
205
195
|
const canDelete = !disabled && !readOnly;
|
|
206
196
|
let matchingOptionValue;
|
|
@@ -261,99 +251,53 @@ const MultiSelect = /*#__PURE__*/React.forwardRef(({
|
|
|
261
251
|
const onFilterChange = useStableCallback(onFilterChangeProp);
|
|
262
252
|
const isFirstRender = useRef(true);
|
|
263
253
|
useEffect(() => {
|
|
264
|
-
if (
|
|
265
|
-
onFilterChange(
|
|
254
|
+
if (!isFirstRender.current) {
|
|
255
|
+
onFilterChange?.(textValue);
|
|
266
256
|
}
|
|
267
|
-
}, [onFilterChange,
|
|
257
|
+
}, [onFilterChange, textValue]);
|
|
268
258
|
useEffect(() => {
|
|
269
259
|
isFirstRender.current = false;
|
|
270
260
|
}, []);
|
|
271
261
|
function handleTextboxClick(event) {
|
|
272
262
|
isMouseDownReported.current = false;
|
|
273
|
-
|
|
274
|
-
|
|
263
|
+
onClick?.(event);
|
|
264
|
+
if (openOnFocus && isOpenedByFocus) {
|
|
265
|
+
setIsOpenedByFocus(false);
|
|
266
|
+
return;
|
|
275
267
|
}
|
|
276
|
-
if (
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
setOpenState(false);
|
|
280
|
-
return;
|
|
281
|
-
}
|
|
282
|
-
onOpen?.();
|
|
283
|
-
setOpenState(true);
|
|
268
|
+
if (open) {
|
|
269
|
+
setTextValue("");
|
|
270
|
+
setOpen(false);
|
|
284
271
|
} else {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}
|
|
288
|
-
function handleDropdownIconClick(event) {
|
|
289
|
-
isMouseDownReported.current = false;
|
|
290
|
-
if (onClick) {
|
|
291
|
-
onClick(event);
|
|
272
|
+
onOpen?.();
|
|
273
|
+
setOpen(true);
|
|
292
274
|
}
|
|
293
|
-
setOpenState(isAlreadyOpen => {
|
|
294
|
-
if (isAlreadyOpen) {
|
|
295
|
-
setFilterText("");
|
|
296
|
-
return false;
|
|
297
|
-
}
|
|
298
|
-
if (onOpen) {
|
|
299
|
-
onOpen();
|
|
300
|
-
}
|
|
301
|
-
return true;
|
|
302
|
-
});
|
|
303
275
|
}
|
|
304
276
|
function handleTextboxBlur(event) {
|
|
305
277
|
isMouseDownOnInput.current = false;
|
|
306
278
|
if (isMouseDownReported.current) {
|
|
307
279
|
return;
|
|
308
280
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
}
|
|
281
|
+
onBlur?.(event);
|
|
282
|
+
setTextValue("");
|
|
283
|
+
setOpen(false);
|
|
313
284
|
}
|
|
314
|
-
function handleTextboxMouseDown(
|
|
285
|
+
function handleTextboxMouseDown() {
|
|
315
286
|
isMouseDownReported.current = true;
|
|
316
|
-
|
|
317
|
-
isMouseDownOnInput.current = true;
|
|
318
|
-
}
|
|
287
|
+
isMouseDownOnInput.current = true;
|
|
319
288
|
}
|
|
320
289
|
function handleListMouseDown() {
|
|
321
290
|
isMouseDownReported.current = true;
|
|
322
291
|
}
|
|
323
292
|
function handleTextboxFocus(event) {
|
|
324
|
-
|
|
293
|
+
onFocus?.(event);
|
|
325
294
|
if (openOnFocus) {
|
|
326
|
-
if (
|
|
327
|
-
|
|
295
|
+
if (open) return;
|
|
296
|
+
onOpen?.();
|
|
297
|
+
if (isMouseDownOnInput.current) {
|
|
298
|
+
setIsOpenedByFocus(true);
|
|
328
299
|
}
|
|
329
|
-
|
|
330
|
-
// we need to use a timeout here as there is a race condition when rendered in a modal
|
|
331
|
-
// whereby the select list isn't visible when the select is auto focused straight away
|
|
332
|
-
focusTimer.current = setTimeout(() => {
|
|
333
|
-
setOpenState(isAlreadyOpen => {
|
|
334
|
-
if (isAlreadyOpen) {
|
|
335
|
-
return true;
|
|
336
|
-
}
|
|
337
|
-
if (onOpen) {
|
|
338
|
-
onOpen();
|
|
339
|
-
}
|
|
340
|
-
if (onFocus && !isInputFocused.current) {
|
|
341
|
-
triggerFocus();
|
|
342
|
-
isInputFocused.current = true;
|
|
343
|
-
}
|
|
344
|
-
if (isMouseDownReported.current && !isMouseDownOnInput.current) {
|
|
345
|
-
isOpenedByFocus.current = false;
|
|
346
|
-
return false;
|
|
347
|
-
}
|
|
348
|
-
if (isMouseDownOnInput.current) {
|
|
349
|
-
isOpenedByFocus.current = true;
|
|
350
|
-
}
|
|
351
|
-
return true;
|
|
352
|
-
});
|
|
353
|
-
});
|
|
354
|
-
} else if (onFocus && !isInputFocused.current) {
|
|
355
|
-
triggerFocus();
|
|
356
|
-
isInputFocused.current = true;
|
|
300
|
+
setOpen(true);
|
|
357
301
|
}
|
|
358
302
|
}
|
|
359
303
|
const onSelectOption = useCallback(optionData => {
|
|
@@ -383,8 +327,8 @@ const MultiSelect = /*#__PURE__*/React.forwardRef(({
|
|
|
383
327
|
}, selectionConfirmed);
|
|
384
328
|
}, [textboxRef, actualValue, updateValue]);
|
|
385
329
|
const onSelectListClose = useCallback(() => {
|
|
386
|
-
|
|
387
|
-
|
|
330
|
+
setOpen(false);
|
|
331
|
+
setTextValue("");
|
|
388
332
|
}, []);
|
|
389
333
|
const assignInput = useCallback(element => {
|
|
390
334
|
if (!element) return;
|
|
@@ -411,8 +355,6 @@ const MultiSelect = /*#__PURE__*/React.forwardRef(({
|
|
|
411
355
|
onMouseDown: handleTextboxMouseDown,
|
|
412
356
|
onFocus: handleTextboxFocus,
|
|
413
357
|
onBlur: handleTextboxBlur,
|
|
414
|
-
iconOnClick: handleDropdownIconClick,
|
|
415
|
-
iconOnMouseDown: handleTextboxMouseDown,
|
|
416
358
|
onKeyDown: handleTextboxKeydown,
|
|
417
359
|
onChange: handleTextboxChange,
|
|
418
360
|
tooltipPosition,
|
|
@@ -441,7 +383,7 @@ const MultiSelect = /*#__PURE__*/React.forwardRef(({
|
|
|
441
383
|
onSelect: onSelectOption,
|
|
442
384
|
onSelectListClose: onSelectListClose,
|
|
443
385
|
onMouseDown: handleListMouseDown,
|
|
444
|
-
filterText:
|
|
386
|
+
filterText: textValue.trim(),
|
|
445
387
|
highlightedValue: highlightedValue,
|
|
446
388
|
noResultsMessage: noResultsMessage,
|
|
447
389
|
isLoading: isLoading,
|
|
@@ -451,7 +393,7 @@ const MultiSelect = /*#__PURE__*/React.forwardRef(({
|
|
|
451
393
|
listMaxHeight: listMaxHeight,
|
|
452
394
|
flipEnabled: flipEnabled,
|
|
453
395
|
multiselectValues: actualValue,
|
|
454
|
-
isOpen:
|
|
396
|
+
isOpen: open,
|
|
455
397
|
enableVirtualScroll: enableVirtualScroll,
|
|
456
398
|
virtualScrollOverscan: virtualScrollOverscan,
|
|
457
399
|
listWidth: listWidth
|
|
@@ -465,7 +407,7 @@ const MultiSelect = /*#__PURE__*/React.forwardRef(({
|
|
|
465
407
|
"data-component": dataComponent,
|
|
466
408
|
"data-role": dataRole,
|
|
467
409
|
"data-element": dataElement,
|
|
468
|
-
isOpen:
|
|
410
|
+
isOpen: open
|
|
469
411
|
}, marginProps), /*#__PURE__*/React.createElement("div", {
|
|
470
412
|
ref: containerRef
|
|
471
413
|
}, /*#__PURE__*/React.createElement(StyledAccessibilityLabelContainer, {
|
|
@@ -479,7 +421,7 @@ const MultiSelect = /*#__PURE__*/React.forwardRef(({
|
|
|
479
421
|
ariaLabel: ariaLabel,
|
|
480
422
|
ariaLabelledby: ariaLabelledby,
|
|
481
423
|
hasTextCursor: true,
|
|
482
|
-
isOpen:
|
|
424
|
+
isOpen: open,
|
|
483
425
|
labelId: labelId
|
|
484
426
|
}, getTextboxProps()))), selectList);
|
|
485
427
|
});
|
|
@@ -6,6 +6,8 @@ export interface DrawerProps extends Omit<TagProps, "data-component"> {
|
|
|
6
6
|
animationDuration?: string;
|
|
7
7
|
/** Specify an aria-label for the Drawer component */
|
|
8
8
|
"aria-label"?: string;
|
|
9
|
+
/** Specify an aria-label for the Drawer sidebar */
|
|
10
|
+
sidebarAriaLabel?: string;
|
|
9
11
|
/** Sets color of sidebar's background */
|
|
10
12
|
backgroundColor?: string;
|
|
11
13
|
children: React.ReactNode;
|
|
@@ -30,6 +32,6 @@ export interface DrawerProps extends Omit<TagProps, "data-component"> {
|
|
|
30
32
|
/** Makes the footer of the drawer sticky. Footer prop must also be set. */
|
|
31
33
|
stickyFooter?: boolean;
|
|
32
34
|
}
|
|
33
|
-
export declare const Drawer: ({ "aria-label": ariaLabel, "data-element": dataElement, "data-role": dataRole, defaultExpanded, expanded, onChange, children, expandedWidth, sidebar, animationDuration, backgroundColor, title, footer, showControls, height, stickyHeader, stickyFooter, }: DrawerProps) => React.JSX.Element;
|
|
35
|
+
export declare const Drawer: ({ "aria-label": ariaLabel, sidebarAriaLabel, "data-element": dataElement, "data-role": dataRole, defaultExpanded, expanded, onChange, children, expandedWidth, sidebar, animationDuration, backgroundColor, title, footer, showControls, height, stickyHeader, stickyFooter, }: DrawerProps) => React.JSX.Element;
|
|
34
36
|
export { DrawerSidebarContext };
|
|
35
37
|
export default Drawer;
|
|
@@ -25,6 +25,7 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
|
|
|
25
25
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
26
26
|
const Drawer = ({
|
|
27
27
|
"aria-label": ariaLabel,
|
|
28
|
+
sidebarAriaLabel,
|
|
28
29
|
"data-element": dataElement,
|
|
29
30
|
"data-role": dataRole = "drawer",
|
|
30
31
|
defaultExpanded = true,
|
|
@@ -107,6 +108,7 @@ const Drawer = ({
|
|
|
107
108
|
}, [toggleAnimation, isExpanded, onChange]);
|
|
108
109
|
const guid = (0, _react.useRef)((0, _guid.default)());
|
|
109
110
|
const sidebarId = `DrawerSidebar_${guid.current}`;
|
|
111
|
+
const titleId = `DrawerTitle_${guid.current}`;
|
|
110
112
|
const getClassNames = (0, _react.useCallback)(() => {
|
|
111
113
|
const classes = [isExpanded ? "open" : "closed"];
|
|
112
114
|
if (isOpening) {
|
|
@@ -144,15 +146,20 @@ const Drawer = ({
|
|
|
144
146
|
ref: drawerSidebarContentRef,
|
|
145
147
|
backgroundColor: backgroundColor,
|
|
146
148
|
"data-element": "drawer-content",
|
|
147
|
-
"data-role": "drawer-content"
|
|
149
|
+
"data-role": "drawer-content",
|
|
150
|
+
"aria-label": sidebarAriaLabel,
|
|
151
|
+
"aria-labelledby": title ? titleId : undefined
|
|
148
152
|
}, stickyHeader && /*#__PURE__*/_react.default.createElement(_drawer.StyledSidebarHeader, {
|
|
149
153
|
"data-role": "drawer-sidebar-header",
|
|
150
154
|
isExpanded: isExpanded
|
|
151
|
-
}, title && /*#__PURE__*/_react.default.createElement(_drawer.StyledSidebarTitle,
|
|
155
|
+
}, title && /*#__PURE__*/_react.default.createElement(_drawer.StyledSidebarTitle, {
|
|
156
|
+
id: titleId
|
|
157
|
+
}, title), getControls()), !stickyHeader && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, title && /*#__PURE__*/_react.default.createElement(_drawer.StyledSidebarTitle, {
|
|
158
|
+
id: titleId
|
|
159
|
+
}, title), getControls()), /*#__PURE__*/_react.default.createElement(_drawer.StyledDrawerSidebar, {
|
|
152
160
|
hasControls: !!showControls,
|
|
153
161
|
id: sidebarId,
|
|
154
162
|
isExpanded: isExpanded,
|
|
155
|
-
role: "navigation",
|
|
156
163
|
overflowY: isExpanded ? "auto" : undefined,
|
|
157
164
|
scrollVariant: "light",
|
|
158
165
|
ref: scrollableContentRef
|
|
@@ -14,7 +14,7 @@ interface StyledDrawerContentProps {
|
|
|
14
14
|
backgroundColor?: string;
|
|
15
15
|
expandedWidth: string;
|
|
16
16
|
}
|
|
17
|
-
declare const StyledDrawerContent: import("styled-components").StyledComponent<"
|
|
17
|
+
declare const StyledDrawerContent: import("styled-components").StyledComponent<"aside", any, StyledDrawerContentProps, never>;
|
|
18
18
|
interface StyledSidebarToggleButtonProps {
|
|
19
19
|
animationDuration?: string;
|
|
20
20
|
isExpanded?: boolean;
|
|
@@ -98,7 +98,7 @@ const buttonClose = () => (0, _styledComponents.keyframes)`
|
|
|
98
98
|
80% {float: right;}
|
|
99
99
|
100% {float: left;}
|
|
100
100
|
`;
|
|
101
|
-
const StyledDrawerContent = exports.StyledDrawerContent = _styledComponents.default.
|
|
101
|
+
const StyledDrawerContent = exports.StyledDrawerContent = _styledComponents.default.aside`
|
|
102
102
|
display: flex;
|
|
103
103
|
flex-direction: column;
|
|
104
104
|
min-width: ${defaultExpandedWidth};
|
|
@@ -20,7 +20,7 @@ export interface NoteProps extends MarginProps {
|
|
|
20
20
|
timeStamp: string;
|
|
21
21
|
};
|
|
22
22
|
/** Adds a Title to the Note */
|
|
23
|
-
title?:
|
|
23
|
+
title?: React.ReactNode;
|
|
24
24
|
/** Set a percentage-based width for the whole Note component, relative to its parent. */
|
|
25
25
|
width?: number;
|
|
26
26
|
}
|
|
@@ -14,6 +14,7 @@ var _actionPopover = require("../action-popover");
|
|
|
14
14
|
var _utils = require("../text-editor/__internal__/utils");
|
|
15
15
|
var _editor = _interopRequireDefault(require("../text-editor/__internal__/editor.context"));
|
|
16
16
|
var _linkPreview = _interopRequireDefault(require("../link-preview"));
|
|
17
|
+
var _typography = _interopRequireDefault(require("../typography"));
|
|
17
18
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
18
19
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
19
20
|
function hasExpectedDisplayName(child, displayName) {
|
|
@@ -57,7 +58,14 @@ const Note = ({
|
|
|
57
58
|
width: width
|
|
58
59
|
}, rest, {
|
|
59
60
|
"data-component": "note"
|
|
60
|
-
}), /*#__PURE__*/_react.default.createElement(_note.StyledNoteMain, null, /*#__PURE__*/_react.default.createElement(_note.StyledNoteContent, null, title &&
|
|
61
|
+
}), /*#__PURE__*/_react.default.createElement(_note.StyledNoteMain, null, /*#__PURE__*/_react.default.createElement(_note.StyledNoteContent, null, title && (typeof title === "string" ? /*#__PURE__*/_react.default.createElement(_typography.default, {
|
|
62
|
+
"data-role": "note-title",
|
|
63
|
+
fontWeight: "700",
|
|
64
|
+
fontSize: "16px",
|
|
65
|
+
lineHeight: "21px",
|
|
66
|
+
paddingBottom: "16px",
|
|
67
|
+
variant: "h2"
|
|
68
|
+
}, title) : /*#__PURE__*/_react.default.createElement(_note.StyledTitleWrapper, null, title)), /*#__PURE__*/_react.default.createElement(_draftJs.Editor, {
|
|
61
69
|
readOnly: true,
|
|
62
70
|
editorState: (0, _utils.getDecoratedValue)(noteContent),
|
|
63
71
|
onChange: /* istanbul ignore next */() => {}
|
|
@@ -3,7 +3,7 @@ declare const StyledNoteContent: import("styled-components").StyledComponent<"di
|
|
|
3
3
|
}, never>;
|
|
4
4
|
declare const StyledNoteMain: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
5
5
|
declare const StyledInlineControl: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
6
|
-
declare const
|
|
6
|
+
declare const StyledTitleWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
7
7
|
declare const StyledFooterContent: import("styled-components").StyledComponent<"div", any, {
|
|
8
8
|
hasName: boolean;
|
|
9
9
|
}, never>;
|
|
@@ -11,4 +11,4 @@ declare const StyledFooter: import("styled-components").StyledComponent<"div", a
|
|
|
11
11
|
declare const StyledNote: import("styled-components").StyledComponent<"div", any, {
|
|
12
12
|
width: number;
|
|
13
13
|
}, never>;
|
|
14
|
-
export { StyledNote, StyledNoteContent, StyledNoteMain, StyledInlineControl,
|
|
14
|
+
export { StyledNote, StyledNoteContent, StyledNoteMain, StyledInlineControl, StyledTitleWrapper, StyledFooter, StyledFooterContent, };
|
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.StyledTitleWrapper = exports.StyledNoteMain = exports.StyledNoteContent = exports.StyledNote = exports.StyledInlineControl = exports.StyledFooterContent = exports.StyledFooter = void 0;
|
|
7
7
|
var _styledComponents = _interopRequireWildcard(require("styled-components"));
|
|
8
8
|
var _styledSystem = require("styled-system");
|
|
9
9
|
var _base = _interopRequireDefault(require("../../style/themes/base"));
|
|
10
10
|
var _linkPreview = require("../link-preview/link-preview.style");
|
|
11
|
+
var _typography = require("../typography/typography.component");
|
|
11
12
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
13
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
13
14
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -20,13 +21,11 @@ const StyledNoteContent = exports.StyledNoteContent = _styledComponents.default.
|
|
|
20
21
|
}) => (0, _styledComponents.css)`
|
|
21
22
|
div.DraftEditor-root {
|
|
22
23
|
min-height: inherit;
|
|
23
|
-
height: 100%;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
div.DraftEditor-editorContainer,
|
|
27
27
|
div.public-DraftEditor-content {
|
|
28
28
|
min-height: inherit;
|
|
29
|
-
height: 100%;
|
|
30
29
|
background-color: var(--colorsUtilityYang100);
|
|
31
30
|
line-height: 21px;
|
|
32
31
|
}
|
|
@@ -49,11 +48,15 @@ const StyledInlineControl = exports.StyledInlineControl = _styledComponents.defa
|
|
|
49
48
|
display: inline-block;
|
|
50
49
|
min-width: fit-content;
|
|
51
50
|
`;
|
|
52
|
-
const
|
|
51
|
+
const StyledTitleWrapper = exports.StyledTitleWrapper = _styledComponents.default.div`
|
|
52
|
+
${_typography.VARIANT_TYPES.map(variant => `
|
|
53
|
+
${variant}{
|
|
53
54
|
font-weight: 700;
|
|
54
55
|
font-size: 16px;
|
|
55
56
|
line-height: 21px;
|
|
56
57
|
padding-bottom: 16px;
|
|
58
|
+
}
|
|
59
|
+
`)}
|
|
57
60
|
`;
|
|
58
61
|
const StyledFooterContent = exports.StyledFooterContent = _styledComponents.default.div`
|
|
59
62
|
line-height: 21px;
|
|
@@ -389,7 +389,7 @@ const SelectList = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
389
389
|
}
|
|
390
390
|
}), ...(flipEnabled ? [(0, _dom.flip)({
|
|
391
391
|
fallbackStrategy: "initialPlacement"
|
|
392
|
-
})] : [])], [listWidth, flipEnabled]);
|
|
392
|
+
})] : /* istanbul ignore next: covered by Playwright tests for reliable positioning in a real browser */[])], [listWidth, flipEnabled]);
|
|
393
393
|
const loader = isLoading ? /*#__PURE__*/_react.default.createElement(_selectList.StyledSelectLoaderContainer, {
|
|
394
394
|
key: "loader"
|
|
395
395
|
}, /*#__PURE__*/_react.default.createElement(_loader.default, null)) : undefined;
|
|
@@ -72,18 +72,16 @@ const MultiSelect = exports.MultiSelect = /*#__PURE__*/_react.default.forwardRef
|
|
|
72
72
|
const accessibilityLabelId = (0, _react.useRef)((0, _guid.default)());
|
|
73
73
|
const containerRef = (0, _react.useRef)(null);
|
|
74
74
|
const listboxRef = (0, _react.useRef)(null);
|
|
75
|
-
const isInputFocused = (0, _react.useRef)(false);
|
|
76
75
|
const isClickTriggeredBySelect = (0, _react.useRef)(false);
|
|
77
76
|
const isMouseDownReported = (0, _react.useRef)(false);
|
|
78
77
|
const isMouseDownOnInput = (0, _react.useRef)(false);
|
|
79
|
-
const isOpenedByFocus = (0, _react.
|
|
78
|
+
const [isOpenedByFocus, setIsOpenedByFocus] = (0, _react.useState)(false);
|
|
80
79
|
const isControlled = (0, _react.useRef)(value !== undefined);
|
|
81
80
|
const [textboxRef, setTextboxRef] = (0, _react.useState)();
|
|
82
|
-
const [
|
|
81
|
+
const [open, setOpen] = (0, _react.useState)(false);
|
|
83
82
|
const [textValue, setTextValue] = (0, _react.useState)("");
|
|
84
83
|
const [selectedValue, setSelectedValue] = (0, _react.useState)(value || defaultValue || []);
|
|
85
84
|
const [highlightedValue, setHighlightedValue] = (0, _react.useState)("");
|
|
86
|
-
const [filterText, setFilterText] = (0, _react.useState)("");
|
|
87
85
|
const [placeholderOverride, setPlaceholderOverride] = (0, _react.useState)();
|
|
88
86
|
const inputId = (0, _react.useRef)(id || (0, _guid.default)());
|
|
89
87
|
const {
|
|
@@ -92,21 +90,12 @@ const MultiSelect = exports.MultiSelect = /*#__PURE__*/_react.default.forwardRef
|
|
|
92
90
|
id: inputId.current,
|
|
93
91
|
label
|
|
94
92
|
});
|
|
95
|
-
const focusTimer = (0, _react.useRef)(null);
|
|
96
93
|
const actualValue = isControlled.current ? value : selectedValue;
|
|
97
94
|
const componentIsUncontrolled = !isControlled || !onChange && defaultValue;
|
|
98
95
|
if (!deprecateUncontrolledWarnTriggered && componentIsUncontrolled) {
|
|
99
96
|
deprecateUncontrolledWarnTriggered = true;
|
|
100
97
|
_logger.default.deprecate("Uncontrolled behaviour in `Multi Select` is deprecated and support will soon be removed. Please make sure all your inputs are controlled.");
|
|
101
98
|
}
|
|
102
|
-
const setOpen = (0, _react.useCallback)(() => {
|
|
103
|
-
setOpenState(isAlreadyOpen => {
|
|
104
|
-
if (!isAlreadyOpen && onOpen) {
|
|
105
|
-
onOpen();
|
|
106
|
-
}
|
|
107
|
-
return true;
|
|
108
|
-
});
|
|
109
|
-
}, [onOpen]);
|
|
110
99
|
const createCustomEvent = (0, _react.useCallback)((newValue, selectionConfirmed) => {
|
|
111
100
|
const customEvent = {
|
|
112
101
|
target: {
|
|
@@ -153,10 +142,12 @@ const MultiSelect = exports.MultiSelect = /*#__PURE__*/_react.default.forwardRef
|
|
|
153
142
|
if (match) {
|
|
154
143
|
setHighlightedValue(match.props.value);
|
|
155
144
|
}
|
|
156
|
-
setFilterText(newValue);
|
|
157
145
|
setTextValue(newValue);
|
|
158
|
-
|
|
159
|
-
|
|
146
|
+
if (!open) {
|
|
147
|
+
onOpen?.();
|
|
148
|
+
}
|
|
149
|
+
setOpen(true);
|
|
150
|
+
}, [children, open, onOpen]);
|
|
160
151
|
const removeSelectedValue = (0, _react.useCallback)(index => {
|
|
161
152
|
isClickTriggeredBySelect.current = true;
|
|
162
153
|
updateValue(previousValue => {
|
|
@@ -173,21 +164,21 @@ const MultiSelect = exports.MultiSelect = /*#__PURE__*/_react.default.forwardRef
|
|
|
173
164
|
key
|
|
174
165
|
} = event;
|
|
175
166
|
const isDeleteKey = key === "Backspace" || key === "Delete";
|
|
176
|
-
|
|
177
|
-
onKeyDown(event);
|
|
178
|
-
}
|
|
167
|
+
onKeyDown?.(event);
|
|
179
168
|
if (readOnly) {
|
|
180
169
|
return;
|
|
181
170
|
}
|
|
182
171
|
if (!event.defaultPrevented && (0, _isNavigationKey.default)(key)) {
|
|
183
172
|
event.preventDefault();
|
|
184
|
-
|
|
173
|
+
if (!open) {
|
|
174
|
+
onOpen?.();
|
|
175
|
+
}
|
|
176
|
+
setOpen(true);
|
|
185
177
|
}
|
|
186
|
-
if (isDeleteKey &&
|
|
178
|
+
if (isDeleteKey && textValue === "") {
|
|
187
179
|
removeSelectedValue(-1);
|
|
188
180
|
}
|
|
189
|
-
|
|
190
|
-
}, [onKeyDown, readOnly, filterText, textValue, setOpen, removeSelectedValue]);
|
|
181
|
+
}, [onKeyDown, readOnly, textValue, open, onOpen, removeSelectedValue]);
|
|
191
182
|
const accessibilityLabel = (0, _react.useMemo)(() => {
|
|
192
183
|
return actualValue && actualValue.length ? _react.default.Children.map(children, child => {
|
|
193
184
|
return /*#__PURE__*/_react.default.isValidElement(child) && actualValue.includes(child.props.value) ? child.props.text : false;
|
|
@@ -197,19 +188,18 @@ const MultiSelect = exports.MultiSelect = /*#__PURE__*/_react.default.forwardRef
|
|
|
197
188
|
}, [children, actualValue]);
|
|
198
189
|
const handleGlobalClick = (0, _react.useCallback)(event => {
|
|
199
190
|
isMouseDownReported.current = false;
|
|
200
|
-
if (!
|
|
191
|
+
if (!open) {
|
|
201
192
|
return;
|
|
202
193
|
}
|
|
203
194
|
const notInContainer = containerRef.current && !containerRef.current.contains(event.target);
|
|
204
195
|
const notInList = listboxRef.current && !listboxRef.current.contains(event.target);
|
|
205
196
|
if (notInContainer && notInList && !isClickTriggeredBySelect.current) {
|
|
206
197
|
setTextValue("");
|
|
207
|
-
setFilterText("");
|
|
208
198
|
setHighlightedValue("");
|
|
209
|
-
|
|
199
|
+
setOpen(false);
|
|
210
200
|
}
|
|
211
201
|
isClickTriggeredBySelect.current = false;
|
|
212
|
-
}, [
|
|
202
|
+
}, [open]);
|
|
213
203
|
const mapValuesToPills = (0, _react.useMemo)(() => {
|
|
214
204
|
const canDelete = !disabled && !readOnly;
|
|
215
205
|
let matchingOptionValue;
|
|
@@ -270,99 +260,53 @@ const MultiSelect = exports.MultiSelect = /*#__PURE__*/_react.default.forwardRef
|
|
|
270
260
|
const onFilterChange = (0, _useStableCallback.default)(onFilterChangeProp);
|
|
271
261
|
const isFirstRender = (0, _react.useRef)(true);
|
|
272
262
|
(0, _react.useEffect)(() => {
|
|
273
|
-
if (
|
|
274
|
-
onFilterChange(
|
|
263
|
+
if (!isFirstRender.current) {
|
|
264
|
+
onFilterChange?.(textValue);
|
|
275
265
|
}
|
|
276
|
-
}, [onFilterChange,
|
|
266
|
+
}, [onFilterChange, textValue]);
|
|
277
267
|
(0, _react.useEffect)(() => {
|
|
278
268
|
isFirstRender.current = false;
|
|
279
269
|
}, []);
|
|
280
270
|
function handleTextboxClick(event) {
|
|
281
271
|
isMouseDownReported.current = false;
|
|
282
|
-
|
|
283
|
-
|
|
272
|
+
onClick?.(event);
|
|
273
|
+
if (openOnFocus && isOpenedByFocus) {
|
|
274
|
+
setIsOpenedByFocus(false);
|
|
275
|
+
return;
|
|
284
276
|
}
|
|
285
|
-
if (
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
setOpenState(false);
|
|
289
|
-
return;
|
|
290
|
-
}
|
|
291
|
-
onOpen?.();
|
|
292
|
-
setOpenState(true);
|
|
277
|
+
if (open) {
|
|
278
|
+
setTextValue("");
|
|
279
|
+
setOpen(false);
|
|
293
280
|
} else {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
}
|
|
297
|
-
function handleDropdownIconClick(event) {
|
|
298
|
-
isMouseDownReported.current = false;
|
|
299
|
-
if (onClick) {
|
|
300
|
-
onClick(event);
|
|
281
|
+
onOpen?.();
|
|
282
|
+
setOpen(true);
|
|
301
283
|
}
|
|
302
|
-
setOpenState(isAlreadyOpen => {
|
|
303
|
-
if (isAlreadyOpen) {
|
|
304
|
-
setFilterText("");
|
|
305
|
-
return false;
|
|
306
|
-
}
|
|
307
|
-
if (onOpen) {
|
|
308
|
-
onOpen();
|
|
309
|
-
}
|
|
310
|
-
return true;
|
|
311
|
-
});
|
|
312
284
|
}
|
|
313
285
|
function handleTextboxBlur(event) {
|
|
314
286
|
isMouseDownOnInput.current = false;
|
|
315
287
|
if (isMouseDownReported.current) {
|
|
316
288
|
return;
|
|
317
289
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
}
|
|
290
|
+
onBlur?.(event);
|
|
291
|
+
setTextValue("");
|
|
292
|
+
setOpen(false);
|
|
322
293
|
}
|
|
323
|
-
function handleTextboxMouseDown(
|
|
294
|
+
function handleTextboxMouseDown() {
|
|
324
295
|
isMouseDownReported.current = true;
|
|
325
|
-
|
|
326
|
-
isMouseDownOnInput.current = true;
|
|
327
|
-
}
|
|
296
|
+
isMouseDownOnInput.current = true;
|
|
328
297
|
}
|
|
329
298
|
function handleListMouseDown() {
|
|
330
299
|
isMouseDownReported.current = true;
|
|
331
300
|
}
|
|
332
301
|
function handleTextboxFocus(event) {
|
|
333
|
-
|
|
302
|
+
onFocus?.(event);
|
|
334
303
|
if (openOnFocus) {
|
|
335
|
-
if (
|
|
336
|
-
|
|
304
|
+
if (open) return;
|
|
305
|
+
onOpen?.();
|
|
306
|
+
if (isMouseDownOnInput.current) {
|
|
307
|
+
setIsOpenedByFocus(true);
|
|
337
308
|
}
|
|
338
|
-
|
|
339
|
-
// we need to use a timeout here as there is a race condition when rendered in a modal
|
|
340
|
-
// whereby the select list isn't visible when the select is auto focused straight away
|
|
341
|
-
focusTimer.current = setTimeout(() => {
|
|
342
|
-
setOpenState(isAlreadyOpen => {
|
|
343
|
-
if (isAlreadyOpen) {
|
|
344
|
-
return true;
|
|
345
|
-
}
|
|
346
|
-
if (onOpen) {
|
|
347
|
-
onOpen();
|
|
348
|
-
}
|
|
349
|
-
if (onFocus && !isInputFocused.current) {
|
|
350
|
-
triggerFocus();
|
|
351
|
-
isInputFocused.current = true;
|
|
352
|
-
}
|
|
353
|
-
if (isMouseDownReported.current && !isMouseDownOnInput.current) {
|
|
354
|
-
isOpenedByFocus.current = false;
|
|
355
|
-
return false;
|
|
356
|
-
}
|
|
357
|
-
if (isMouseDownOnInput.current) {
|
|
358
|
-
isOpenedByFocus.current = true;
|
|
359
|
-
}
|
|
360
|
-
return true;
|
|
361
|
-
});
|
|
362
|
-
});
|
|
363
|
-
} else if (onFocus && !isInputFocused.current) {
|
|
364
|
-
triggerFocus();
|
|
365
|
-
isInputFocused.current = true;
|
|
309
|
+
setOpen(true);
|
|
366
310
|
}
|
|
367
311
|
}
|
|
368
312
|
const onSelectOption = (0, _react.useCallback)(optionData => {
|
|
@@ -392,8 +336,8 @@ const MultiSelect = exports.MultiSelect = /*#__PURE__*/_react.default.forwardRef
|
|
|
392
336
|
}, selectionConfirmed);
|
|
393
337
|
}, [textboxRef, actualValue, updateValue]);
|
|
394
338
|
const onSelectListClose = (0, _react.useCallback)(() => {
|
|
395
|
-
|
|
396
|
-
|
|
339
|
+
setOpen(false);
|
|
340
|
+
setTextValue("");
|
|
397
341
|
}, []);
|
|
398
342
|
const assignInput = (0, _react.useCallback)(element => {
|
|
399
343
|
if (!element) return;
|
|
@@ -420,8 +364,6 @@ const MultiSelect = exports.MultiSelect = /*#__PURE__*/_react.default.forwardRef
|
|
|
420
364
|
onMouseDown: handleTextboxMouseDown,
|
|
421
365
|
onFocus: handleTextboxFocus,
|
|
422
366
|
onBlur: handleTextboxBlur,
|
|
423
|
-
iconOnClick: handleDropdownIconClick,
|
|
424
|
-
iconOnMouseDown: handleTextboxMouseDown,
|
|
425
367
|
onKeyDown: handleTextboxKeydown,
|
|
426
368
|
onChange: handleTextboxChange,
|
|
427
369
|
tooltipPosition,
|
|
@@ -450,7 +392,7 @@ const MultiSelect = exports.MultiSelect = /*#__PURE__*/_react.default.forwardRef
|
|
|
450
392
|
onSelect: onSelectOption,
|
|
451
393
|
onSelectListClose: onSelectListClose,
|
|
452
394
|
onMouseDown: handleListMouseDown,
|
|
453
|
-
filterText:
|
|
395
|
+
filterText: textValue.trim(),
|
|
454
396
|
highlightedValue: highlightedValue,
|
|
455
397
|
noResultsMessage: noResultsMessage,
|
|
456
398
|
isLoading: isLoading,
|
|
@@ -460,7 +402,7 @@ const MultiSelect = exports.MultiSelect = /*#__PURE__*/_react.default.forwardRef
|
|
|
460
402
|
listMaxHeight: listMaxHeight,
|
|
461
403
|
flipEnabled: flipEnabled,
|
|
462
404
|
multiselectValues: actualValue,
|
|
463
|
-
isOpen:
|
|
405
|
+
isOpen: open,
|
|
464
406
|
enableVirtualScroll: enableVirtualScroll,
|
|
465
407
|
virtualScrollOverscan: virtualScrollOverscan,
|
|
466
408
|
listWidth: listWidth
|
|
@@ -474,7 +416,7 @@ const MultiSelect = exports.MultiSelect = /*#__PURE__*/_react.default.forwardRef
|
|
|
474
416
|
"data-component": dataComponent,
|
|
475
417
|
"data-role": dataRole,
|
|
476
418
|
"data-element": dataElement,
|
|
477
|
-
isOpen:
|
|
419
|
+
isOpen: open
|
|
478
420
|
}, marginProps), /*#__PURE__*/_react.default.createElement("div", {
|
|
479
421
|
ref: containerRef
|
|
480
422
|
}, /*#__PURE__*/_react.default.createElement(_multiSelect.StyledAccessibilityLabelContainer, {
|
|
@@ -488,7 +430,7 @@ const MultiSelect = exports.MultiSelect = /*#__PURE__*/_react.default.forwardRef
|
|
|
488
430
|
ariaLabel: ariaLabel,
|
|
489
431
|
ariaLabelledby: ariaLabelledby,
|
|
490
432
|
hasTextCursor: true,
|
|
491
|
-
isOpen:
|
|
433
|
+
isOpen: open,
|
|
492
434
|
labelId: labelId
|
|
493
435
|
}, getTextboxProps()))), selectList);
|
|
494
436
|
});
|