@workday/canvas-kit-react 10.3.2 → 10.3.5
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/collection/lib/useCursorListModel.tsx +86 -90
- package/collection/lib/useListItemAllowChildStrings.ts +3 -3
- package/collection/lib/useListRenderItem.tsx +1 -1
- package/combobox/lib/hooks/useComboboxKeyboardTypeAhead.ts +3 -3
- package/combobox/lib/hooks/useComboboxModel.tsx +1 -2
- package/common/README.md +32 -14
- package/common/lib/styles/errorRing.ts +2 -2
- package/common/lib/styles/focusRing.ts +4 -17
- package/dist/commonjs/avatar/lib/Avatar.js +1 -1
- package/dist/commonjs/banner/lib/Banner.js +1 -1
- package/dist/commonjs/button/lib/BaseButton.js +22 -22
- package/dist/commonjs/button/lib/DeleteButton.js +1 -1
- package/dist/commonjs/button/lib/PrimaryButton.js +2 -2
- package/dist/commonjs/button/lib/SecondaryButton.js +2 -2
- package/dist/commonjs/button/lib/TertiaryButton.js +15 -15
- package/dist/commonjs/button/lib/ToolbarDropdownButton.js +6 -1
- package/dist/commonjs/button/lib/ToolbarIconButton.js +6 -1
- package/dist/commonjs/button/lib/deprecated_Button.js +2 -2
- package/dist/commonjs/checkbox/lib/Checkbox.js +14 -2
- package/dist/commonjs/collection/lib/useCursorListModel.d.ts.map +1 -1
- package/dist/commonjs/collection/lib/useListItemAllowChildStrings.d.ts +2 -1
- package/dist/commonjs/collection/lib/useListItemAllowChildStrings.d.ts.map +1 -1
- package/dist/commonjs/collection/lib/useListItemAllowChildStrings.js +1 -1
- package/dist/commonjs/collection/lib/useListRenderItem.js +1 -1
- package/dist/commonjs/combobox/lib/hooks/useComboboxKeyboardTypeAhead.js +2 -3
- package/dist/commonjs/combobox/lib/hooks/useComboboxModel.d.ts.map +1 -1
- package/dist/commonjs/combobox/lib/hooks/useComboboxModel.js +1 -2
- package/dist/commonjs/common/lib/AccessibleHide.js +1 -1
- package/dist/commonjs/common/lib/CanvasProvider.js +1 -1
- package/dist/commonjs/common/lib/styles/errorRing.js +2 -2
- package/dist/commonjs/common/lib/styles/focusRing.d.ts.map +1 -1
- package/dist/commonjs/common/lib/styles/focusRing.js +5 -16
- package/dist/commonjs/radio/lib/Radio.js +17 -3
- package/dist/commonjs/select/lib/Select.d.ts +2 -1
- package/dist/commonjs/select/lib/Select.d.ts.map +1 -1
- package/dist/commonjs/select/lib/Select.js +5 -3
- package/dist/commonjs/select/lib/hooks/useSelectInput.d.ts +6 -1
- package/dist/commonjs/select/lib/hooks/useSelectInput.d.ts.map +1 -1
- package/dist/commonjs/select/lib/hooks/useSelectInput.js +45 -4
- package/dist/commonjs/select/lib/hooks/useSelectModel.d.ts.map +1 -1
- package/dist/commonjs/select/lib/hooks/useSelectModel.js +1 -2
- package/dist/commonjs/switch/lib/Switch.js +2 -2
- package/dist/commonjs/tabs/lib/TabsItem.js +1 -1
- package/dist/commonjs/text-input/lib/TextInput.js +3 -3
- package/dist/es6/avatar/lib/Avatar.js +1 -1
- package/dist/es6/banner/lib/Banner.js +1 -1
- package/dist/es6/button/lib/BaseButton.js +22 -22
- package/dist/es6/button/lib/DeleteButton.js +1 -1
- package/dist/es6/button/lib/PrimaryButton.js +2 -2
- package/dist/es6/button/lib/SecondaryButton.js +2 -2
- package/dist/es6/button/lib/TertiaryButton.js +15 -15
- package/dist/es6/button/lib/ToolbarDropdownButton.js +6 -1
- package/dist/es6/button/lib/ToolbarIconButton.js +6 -1
- package/dist/es6/button/lib/deprecated_Button.js +2 -2
- package/dist/es6/checkbox/lib/Checkbox.js +14 -2
- package/dist/es6/collection/lib/useCursorListModel.d.ts.map +1 -1
- package/dist/es6/collection/lib/useListItemAllowChildStrings.d.ts +2 -1
- package/dist/es6/collection/lib/useListItemAllowChildStrings.d.ts.map +1 -1
- package/dist/es6/collection/lib/useListItemAllowChildStrings.js +1 -1
- package/dist/es6/collection/lib/useListRenderItem.js +1 -1
- package/dist/es6/combobox/lib/hooks/useComboboxKeyboardTypeAhead.js +2 -3
- package/dist/es6/combobox/lib/hooks/useComboboxModel.d.ts.map +1 -1
- package/dist/es6/combobox/lib/hooks/useComboboxModel.js +1 -2
- package/dist/es6/common/lib/AccessibleHide.js +1 -1
- package/dist/es6/common/lib/CanvasProvider.js +1 -1
- package/dist/es6/common/lib/styles/errorRing.js +2 -2
- package/dist/es6/common/lib/styles/focusRing.d.ts.map +1 -1
- package/dist/es6/common/lib/styles/focusRing.js +5 -16
- package/dist/es6/radio/lib/Radio.js +17 -3
- package/dist/es6/select/lib/Select.d.ts +2 -1
- package/dist/es6/select/lib/Select.d.ts.map +1 -1
- package/dist/es6/select/lib/Select.js +5 -3
- package/dist/es6/select/lib/hooks/useSelectInput.d.ts +6 -1
- package/dist/es6/select/lib/hooks/useSelectInput.d.ts.map +1 -1
- package/dist/es6/select/lib/hooks/useSelectInput.js +43 -5
- package/dist/es6/select/lib/hooks/useSelectModel.d.ts.map +1 -1
- package/dist/es6/select/lib/hooks/useSelectModel.js +1 -2
- package/dist/es6/switch/lib/Switch.js +2 -2
- package/dist/es6/tabs/lib/TabsItem.js +1 -1
- package/dist/es6/text-input/lib/TextInput.js +3 -3
- package/package.json +4 -4
- package/select/lib/Select.tsx +50 -4
- package/select/lib/hooks/useSelectInput.ts +86 -44
- package/select/lib/hooks/useSelectModel.tsx +1 -2
- package/text-input/lib/TextInput.tsx +3 -3
|
@@ -85,17 +85,31 @@ const RadioInput = styled('input')({
|
|
|
85
85
|
borderWidth: '2px',
|
|
86
86
|
borderColor: variant === 'inverse' ? colors.blackPepper400 : themeFocusOutline,
|
|
87
87
|
boxShadow: 'none',
|
|
88
|
-
...
|
|
88
|
+
...focusRing({
|
|
89
|
+
width: variant === 'inverse' ? 2 : 0,
|
|
90
|
+
separation: 0,
|
|
91
|
+
animate: false,
|
|
92
|
+
innerColor: variant === 'inverse' ? colors.blackPepper400 : undefined,
|
|
93
|
+
outerColor: variant === 'inverse' ? colors.frenchVanilla100 : undefined,
|
|
94
|
+
}),
|
|
89
95
|
},
|
|
90
96
|
},
|
|
91
97
|
'&:checked:focus ~ div:first-of-type': {
|
|
92
|
-
...
|
|
98
|
+
...focusRing({
|
|
99
|
+
separation: 2,
|
|
100
|
+
width: 2,
|
|
101
|
+
innerColor: variant === 'inverse' ? colors.blackPepper400 : undefined,
|
|
102
|
+
outerColor: variant === 'inverse' ? colors.frenchVanilla100 : themeFocusOutline,
|
|
103
|
+
}),
|
|
93
104
|
borderColor: variant === 'inverse' ? colors.frenchVanilla100 : themePrimary.main,
|
|
94
105
|
borderWidth: '2px',
|
|
95
106
|
},
|
|
96
107
|
...mouseFocusBehavior({
|
|
97
108
|
'&:focus ~ div:first-of-type': {
|
|
98
|
-
...
|
|
109
|
+
...focusRing({
|
|
110
|
+
width: 0,
|
|
111
|
+
outerColor: variant === 'inverse' ? colors.frenchVanilla100 : themeFocusOutline,
|
|
112
|
+
}),
|
|
99
113
|
borderWidth: '1px',
|
|
100
114
|
borderColor: checked
|
|
101
115
|
? variant === 'inverse'
|
|
@@ -3,7 +3,8 @@ import { ExtractProps, Themeable } from '@workday/canvas-kit-react/common';
|
|
|
3
3
|
import { Combobox } from '@workday/canvas-kit-react/combobox';
|
|
4
4
|
import { TextInput } from '@workday/canvas-kit-react/text-input';
|
|
5
5
|
import { CanvasSystemIcon } from '@workday/design-assets-types';
|
|
6
|
-
|
|
6
|
+
import { CSProps } from '@workday/canvas-kit-styling';
|
|
7
|
+
export interface SelectInputProps extends ExtractProps<typeof TextInput>, CSProps {
|
|
7
8
|
/**
|
|
8
9
|
* The Icon to render at the start of the `input`. Use this prop if your options
|
|
9
10
|
* include icons that you would like to render in the `input` when selected.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Select.d.ts","sourceRoot":"","sources":["../../../../select/lib/Select.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAEL,YAAY,EAEZ,SAAS,EACV,MAAM,kCAAkC,CAAC;AAC1C,OAAO,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAEH;;;;;;;;;;;;;;;;;OAiBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAEH;;;;;;;;;;;;;;;;;OAiBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CASL,CAAC"}
|
|
@@ -9,15 +9,17 @@ import { useSelectModel } from './hooks/useSelectModel';
|
|
|
9
9
|
import { useSelectCard } from './hooks/useSelectCard';
|
|
10
10
|
import { useSelectInput } from './hooks/useSelectInput';
|
|
11
11
|
import { createStyles } from '@workday/canvas-kit-styling';
|
|
12
|
-
const selectInputStyles = createStyles({ name: "
|
|
12
|
+
const selectInputStyles = createStyles({ name: "1gpclr4", styles: "caret-color:transparent;cursor:default;&::selection{background-color:transparent;}" });
|
|
13
|
+
const hiddenSelectStyles = createStyles({ name: "1uxiz6e", styles: "position:absolute;top:0px;bottom:0px;left:0px;right:0px;opacity:0px;cursor:default;pointer-events:none;" });
|
|
13
14
|
export const SelectInput = createSubcomponent(TextInput)({
|
|
14
15
|
modelHook: useSelectModel,
|
|
15
16
|
elemPropsHook: useSelectInput,
|
|
16
|
-
})(({ placeholder = 'Choose an option', inputStartIcon, ...elemProps }, Element, model) => {
|
|
17
|
+
})(({ placeholder = 'Choose an option', inputStartIcon, error, textInputProps, disabled, ref, onChange, onInput, onFocus, value, name, ...elemProps }, Element, model) => {
|
|
17
18
|
return (React.createElement(InputGroup, null,
|
|
18
19
|
inputStartIcon && model.state.selectedIds.length > 0 && (React.createElement(InputGroup.InnerStart, { pointerEvents: "none" },
|
|
19
20
|
React.createElement(SystemIcon, { icon: inputStartIcon }))),
|
|
20
|
-
React.createElement(InputGroup.Input,
|
|
21
|
+
React.createElement(InputGroup.Input, { error: error, disabled: disabled, className: hiddenSelectStyles, tabIndex: -1, "aria-hidden": true, onChange: onChange, onInput: onInput, value: value, onFocus: onFocus, name: name, ref: ref }),
|
|
22
|
+
React.createElement(InputGroup.Input, Object.assign({ as: Element, disabled: disabled, placeholder: placeholder, error: error }, textInputProps, mergeStyles(elemProps, [selectInputStyles]))),
|
|
21
23
|
React.createElement(InputGroup.InnerEnd, { position: "absolute", pointerEvents: "none" },
|
|
22
24
|
React.createElement(SystemIcon, { icon: caretDownSmallIcon }))));
|
|
23
25
|
});
|
|
@@ -80,8 +80,13 @@ export declare const useSelectInput: import("@workday/canvas-kit-react/common").
|
|
|
80
80
|
getId: (item: any) => string;
|
|
81
81
|
}, {
|
|
82
82
|
readonly onKeyDown: (event: React.KeyboardEvent) => void;
|
|
83
|
-
readonly
|
|
83
|
+
readonly onChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
|
|
84
84
|
readonly autoComplete: "off";
|
|
85
|
+
readonly onFocus: () => void;
|
|
86
|
+
readonly textInputProps: {
|
|
87
|
+
readonly ref: React.RefObject<HTMLInputElement>;
|
|
88
|
+
};
|
|
89
|
+
readonly ref: (instance: HTMLInputElement | null) => void;
|
|
85
90
|
readonly defaultValue: string | undefined;
|
|
86
91
|
} & {
|
|
87
92
|
onKeyDown(event: React.KeyboardEvent<Element>): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSelectInput.d.ts","sourceRoot":"","sources":["../../../../../select/lib/hooks/useSelectInput.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAgB1B;;GAEG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"useSelectInput.d.ts","sourceRoot":"","sources":["../../../../../select/lib/hooks/useSelectInput.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAgB1B;;GAEG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gCA8CF,mBAAmB;+BAvCP,MAAM,WAAW,CAAC,gBAAgB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0FvE,CAAC"}
|
|
@@ -1,13 +1,24 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { composeHooks, createElemPropsHook, useLocalRef, useResizeObserver, dispatchInputEvent, } from '@workday/canvas-kit-react/common';
|
|
2
3
|
import { useComboboxInput, useComboboxKeyboardTypeAhead, useComboboxMoveCursorToSelected, useComboboxResetCursorToSelected, } from '@workday/canvas-kit-react/combobox';
|
|
3
4
|
import { useSelectModel } from './useSelectModel';
|
|
4
5
|
/**
|
|
5
6
|
* `useSelectInput` extends {@link useComboboxInput useComboboxInput} and {@link useComboboxKeyboardTypeAhead useComboboxKeyboardTypeAhead} and adds type ahead functionality and Select-specific [keyboard support](https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/).
|
|
6
7
|
*/
|
|
7
8
|
export const useSelectInput = composeHooks(createElemPropsHook(useSelectModel)((model, ref, elemProps = {}) => {
|
|
8
|
-
const {
|
|
9
|
+
const { elementRef } = useLocalRef(ref);
|
|
10
|
+
const textInputRef = React.useRef(null);
|
|
11
|
+
// Update the text value of the input
|
|
12
|
+
const handleOnChange = (event) => {
|
|
13
|
+
var _a;
|
|
14
|
+
const value = (_a = model.navigation.getItem(event.target.value, model)) === null || _a === void 0 ? void 0 : _a.textValue;
|
|
15
|
+
const nativeInputValue = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(textInputRef.current), 'value');
|
|
16
|
+
if (nativeInputValue && nativeInputValue.set) {
|
|
17
|
+
nativeInputValue.set.call(textInputRef.current, value);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
9
20
|
useResizeObserver({
|
|
10
|
-
ref:
|
|
21
|
+
ref: textInputRef,
|
|
11
22
|
onResize: data => {
|
|
12
23
|
if (model.state.visibility === 'visible') {
|
|
13
24
|
// Width of the Input + 2px border + 8px padding
|
|
@@ -16,6 +27,20 @@ export const useSelectInput = composeHooks(createElemPropsHook(useSelectModel)((
|
|
|
16
27
|
}
|
|
17
28
|
},
|
|
18
29
|
});
|
|
30
|
+
// The intent is if items are loaded after the component is rendered, it will update the input with the value.
|
|
31
|
+
// **Note: We might need to watch for other things or how often we should do this**
|
|
32
|
+
React.useEffect(() => {
|
|
33
|
+
if (model.state.inputRef.current &&
|
|
34
|
+
model.state.items.length > 0 &&
|
|
35
|
+
model.state.selectedIds[0]) {
|
|
36
|
+
const value = model.navigation.getItem(model.state.selectedIds[0], model).id;
|
|
37
|
+
if (model.state.inputRef.current.value !== value) {
|
|
38
|
+
// Programmatically dispatch an onChange once items are loaded. This account for when a consumer wants an initial selected item and they're loading them from a server.
|
|
39
|
+
dispatchInputEvent(model.state.inputRef.current, value);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
43
|
+
}, [model.state.inputRef, model.state.items.length]);
|
|
19
44
|
return {
|
|
20
45
|
onKeyDown(event) {
|
|
21
46
|
// Prevent the keys from being enter in the input
|
|
@@ -39,8 +64,21 @@ export const useSelectInput = composeHooks(createElemPropsHook(useSelectModel)((
|
|
|
39
64
|
}
|
|
40
65
|
}
|
|
41
66
|
},
|
|
42
|
-
|
|
67
|
+
onChange: handleOnChange,
|
|
43
68
|
autoComplete: 'off',
|
|
44
|
-
|
|
69
|
+
// When the hidden input is focused, we want to show the focus/hover states of the input that sits below it.
|
|
70
|
+
onFocus() {
|
|
71
|
+
var _a;
|
|
72
|
+
(_a = textInputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
73
|
+
},
|
|
74
|
+
textInputProps: {
|
|
75
|
+
ref: textInputRef,
|
|
76
|
+
},
|
|
77
|
+
ref: elementRef,
|
|
78
|
+
// Account for the case where an initial item is selected when the Select first renders
|
|
79
|
+
defaultValue: model.state.selectedIds.length > 0 && model.state.items.length > 0
|
|
80
|
+
? model.navigation.getItem(model.state.selectedIds[0], model).textValue ||
|
|
81
|
+
model.state.value
|
|
82
|
+
: undefined,
|
|
45
83
|
};
|
|
46
84
|
}), useComboboxKeyboardTypeAhead, useComboboxResetCursorToSelected, useComboboxMoveCursorToSelected, useComboboxInput);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSelectModel.d.ts","sourceRoot":"","sources":["../../../../../select/lib/hooks/useSelectModel.tsx"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;EAWzB,CAAC"}
|
|
@@ -31,7 +31,7 @@ const SwitchInput = styled('input')({
|
|
|
31
31
|
'&:focus': {
|
|
32
32
|
outline: 'none',
|
|
33
33
|
'& ~ div:first-of-type': {
|
|
34
|
-
...{
|
|
34
|
+
...focusRing({ separation: 2, animate: false }, theme),
|
|
35
35
|
},
|
|
36
36
|
},
|
|
37
37
|
'& ~ div:first-of-type': {
|
|
@@ -41,7 +41,7 @@ const SwitchInput = styled('input')({
|
|
|
41
41
|
0 0 0 5px ${errorColors.outer}`,
|
|
42
42
|
},
|
|
43
43
|
'&:focus ~ div:first-of-type': {
|
|
44
|
-
...{
|
|
44
|
+
...focusRing({ separation: 2, animate: false }, theme),
|
|
45
45
|
},
|
|
46
46
|
};
|
|
47
47
|
return {
|
|
@@ -31,7 +31,7 @@ export const StyledTabItem = styled(Box.as('button'))(({ theme }) => ({
|
|
|
31
31
|
},
|
|
32
32
|
'&:focus': {
|
|
33
33
|
outline: `none`,
|
|
34
|
-
...{
|
|
34
|
+
...focusRing({ inset: 'outer', width: 0, separation: 2 }, theme),
|
|
35
35
|
},
|
|
36
36
|
'&:disabled, &[aria-disabled]': {
|
|
37
37
|
color: colors.licorice100,
|
|
@@ -15,10 +15,10 @@ const StyledTextInput = styled('input')({
|
|
|
15
15
|
'&::placeholder': {
|
|
16
16
|
color: inputColors.placeholder,
|
|
17
17
|
},
|
|
18
|
-
'&:hover': {
|
|
18
|
+
'&:hover, &.hover': {
|
|
19
19
|
borderColor: inputColors.hoverBorder,
|
|
20
20
|
},
|
|
21
|
-
'&:focus:not([disabled])': {
|
|
21
|
+
'&:focus-visible:not([disabled]), &.focus:not([disabled]), &:focus:not([disabled])': {
|
|
22
22
|
borderColor: inputColors.focusBorder,
|
|
23
23
|
boxShadow: `inset 0 0 0 1px ${inputColors.focusBorder}`,
|
|
24
24
|
outline: 'none',
|
|
@@ -41,7 +41,7 @@ const StyledTextInput = styled('input')({
|
|
|
41
41
|
width: '100%',
|
|
42
42
|
}, ({ theme, error }) => {
|
|
43
43
|
return {
|
|
44
|
-
'&:focus:not([disabled])': {
|
|
44
|
+
'&:focus-visible:not([disabled]), &.focus:not([disabled])': {
|
|
45
45
|
borderColor: theme.canvas.palette.common.focusOutline,
|
|
46
46
|
boxShadow: `inset 0 0 0 1px ${theme.canvas.palette.common.focusOutline}`,
|
|
47
47
|
outline: 'none',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workday/canvas-kit-react",
|
|
3
|
-
"version": "10.3.
|
|
3
|
+
"version": "10.3.5",
|
|
4
4
|
"description": "The parent module that contains all Workday Canvas Kit React components",
|
|
5
5
|
"author": "Workday, Inc. (https://www.workday.com)",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"@emotion/styled": "^11.6.0",
|
|
51
51
|
"@popperjs/core": "^2.5.4",
|
|
52
52
|
"@workday/canvas-colors-web": "^2.0.0",
|
|
53
|
-
"@workday/canvas-kit-popup-stack": "^10.3.
|
|
54
|
-
"@workday/canvas-kit-styling": "^10.3.
|
|
53
|
+
"@workday/canvas-kit-popup-stack": "^10.3.5",
|
|
54
|
+
"@workday/canvas-kit-styling": "^10.3.5",
|
|
55
55
|
"@workday/canvas-system-icons-web": "^3.0.0",
|
|
56
56
|
"@workday/canvas-tokens-web": "^1.0.0",
|
|
57
57
|
"@workday/design-assets-types": "^0.2.8",
|
|
@@ -69,5 +69,5 @@
|
|
|
69
69
|
"@workday/canvas-accent-icons-web": "^3.0.0",
|
|
70
70
|
"@workday/canvas-applet-icons-web": "^2.0.0"
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "ff2e0a2ef7bfedfa90006e0195ac8fcc1039b39c"
|
|
73
73
|
}
|
package/select/lib/Select.tsx
CHANGED
|
@@ -15,9 +15,9 @@ import {useSelectModel} from './hooks/useSelectModel';
|
|
|
15
15
|
import {useSelectCard} from './hooks/useSelectCard';
|
|
16
16
|
import {useSelectInput} from './hooks/useSelectInput';
|
|
17
17
|
import {CanvasSystemIcon} from '@workday/design-assets-types';
|
|
18
|
-
import {createStyles} from '@workday/canvas-kit-styling';
|
|
18
|
+
import {createStyles, CSProps} from '@workday/canvas-kit-styling';
|
|
19
19
|
|
|
20
|
-
export interface SelectInputProps extends ExtractProps<typeof TextInput
|
|
20
|
+
export interface SelectInputProps extends ExtractProps<typeof TextInput>, CSProps {
|
|
21
21
|
/**
|
|
22
22
|
* The Icon to render at the start of the `input`. Use this prop if your options
|
|
23
23
|
* include icons that you would like to render in the `input` when selected.
|
|
@@ -34,11 +34,39 @@ const selectInputStyles = createStyles({
|
|
|
34
34
|
},
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
+
const hiddenSelectStyles = createStyles({
|
|
38
|
+
position: 'absolute',
|
|
39
|
+
top: 0,
|
|
40
|
+
bottom: 0,
|
|
41
|
+
left: 0,
|
|
42
|
+
right: 0,
|
|
43
|
+
opacity: 0,
|
|
44
|
+
cursor: 'default',
|
|
45
|
+
pointerEvents: 'none',
|
|
46
|
+
});
|
|
47
|
+
|
|
37
48
|
export const SelectInput = createSubcomponent(TextInput)({
|
|
38
49
|
modelHook: useSelectModel,
|
|
39
50
|
elemPropsHook: useSelectInput,
|
|
40
51
|
})<SelectInputProps>(
|
|
41
|
-
(
|
|
52
|
+
(
|
|
53
|
+
{
|
|
54
|
+
placeholder = 'Choose an option',
|
|
55
|
+
inputStartIcon,
|
|
56
|
+
error,
|
|
57
|
+
textInputProps,
|
|
58
|
+
disabled,
|
|
59
|
+
ref,
|
|
60
|
+
onChange,
|
|
61
|
+
onInput,
|
|
62
|
+
onFocus,
|
|
63
|
+
value,
|
|
64
|
+
name,
|
|
65
|
+
...elemProps
|
|
66
|
+
},
|
|
67
|
+
Element,
|
|
68
|
+
model
|
|
69
|
+
) => {
|
|
42
70
|
return (
|
|
43
71
|
<InputGroup>
|
|
44
72
|
{inputStartIcon && model.state.selectedIds.length > 0 && (
|
|
@@ -46,11 +74,29 @@ export const SelectInput = createSubcomponent(TextInput)({
|
|
|
46
74
|
<SystemIcon icon={inputStartIcon} />
|
|
47
75
|
</InputGroup.InnerStart>
|
|
48
76
|
)}
|
|
77
|
+
{/* Hidden input to handle ids */}
|
|
78
|
+
<InputGroup.Input
|
|
79
|
+
error={error}
|
|
80
|
+
disabled={disabled}
|
|
81
|
+
className={hiddenSelectStyles}
|
|
82
|
+
tabIndex={-1}
|
|
83
|
+
aria-hidden={true}
|
|
84
|
+
onChange={onChange}
|
|
85
|
+
onInput={onInput}
|
|
86
|
+
value={value}
|
|
87
|
+
onFocus={onFocus}
|
|
88
|
+
name={name}
|
|
89
|
+
ref={ref}
|
|
90
|
+
/>
|
|
91
|
+
{/* Visual input */}
|
|
49
92
|
<InputGroup.Input
|
|
50
93
|
as={Element}
|
|
94
|
+
disabled={disabled}
|
|
51
95
|
placeholder={placeholder}
|
|
96
|
+
error={error}
|
|
97
|
+
{...textInputProps}
|
|
52
98
|
{...mergeStyles(elemProps, [selectInputStyles])}
|
|
53
|
-
|
|
99
|
+
/>
|
|
54
100
|
<InputGroup.InnerEnd position="absolute" pointerEvents="none">
|
|
55
101
|
<SystemIcon icon={caretDownSmallIcon} />
|
|
56
102
|
</InputGroup.InnerEnd>
|
|
@@ -2,9 +2,9 @@ import React from 'react';
|
|
|
2
2
|
import {
|
|
3
3
|
composeHooks,
|
|
4
4
|
createElemPropsHook,
|
|
5
|
-
useForkRef,
|
|
6
5
|
useLocalRef,
|
|
7
6
|
useResizeObserver,
|
|
7
|
+
dispatchInputEvent,
|
|
8
8
|
} from '@workday/canvas-kit-react/common';
|
|
9
9
|
import {
|
|
10
10
|
useComboboxInput,
|
|
@@ -18,56 +18,98 @@ import {useSelectModel} from './useSelectModel';
|
|
|
18
18
|
* `useSelectInput` extends {@link useComboboxInput useComboboxInput} and {@link useComboboxKeyboardTypeAhead useComboboxKeyboardTypeAhead} and adds type ahead functionality and Select-specific [keyboard support](https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/).
|
|
19
19
|
*/
|
|
20
20
|
export const useSelectInput = composeHooks(
|
|
21
|
-
createElemPropsHook(useSelectModel)(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
createElemPropsHook(useSelectModel)(
|
|
22
|
+
(model, ref, elemProps: {keySofar?: string; placeholder?: string} = {}) => {
|
|
23
|
+
const {elementRef} = useLocalRef<HTMLInputElement>(ref as any);
|
|
24
|
+
const textInputRef = React.useRef<HTMLInputElement>(null);
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
// Update the text value of the input
|
|
27
|
+
const handleOnChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
28
|
+
const value = model.navigation.getItem(event.target.value, model)?.textValue;
|
|
29
|
+
const nativeInputValue = Object.getOwnPropertyDescriptor(
|
|
30
|
+
Object.getPrototypeOf(textInputRef.current),
|
|
31
|
+
'value'
|
|
32
|
+
);
|
|
33
|
+
if (nativeInputValue && nativeInputValue.set) {
|
|
34
|
+
nativeInputValue.set.call(textInputRef.current, value);
|
|
33
35
|
}
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
+
};
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
// if the menu is visible
|
|
38
|
+
useResizeObserver({
|
|
39
|
+
ref: textInputRef,
|
|
40
|
+
onResize: data => {
|
|
41
|
+
if (model.state.visibility === 'visible') {
|
|
42
|
+
// Width of the Input + 2px border + 8px padding
|
|
43
|
+
const calculatedWidth = data.width ? data.width + 42 + 8 : 0;
|
|
44
|
+
model.events.setWidth(calculatedWidth);
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
// The intent is if items are loaded after the component is rendered, it will update the input with the value.
|
|
49
|
+
// **Note: We might need to watch for other things or how often we should do this**
|
|
50
|
+
React.useEffect(() => {
|
|
52
51
|
if (
|
|
53
|
-
|
|
54
|
-
model.state.
|
|
52
|
+
model.state.inputRef.current &&
|
|
53
|
+
model.state.items.length > 0 &&
|
|
54
|
+
model.state.selectedIds[0]
|
|
55
55
|
) {
|
|
56
|
-
|
|
57
|
-
if (
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
});
|
|
61
|
-
model.events.hide();
|
|
56
|
+
const value = model.navigation.getItem(model.state.selectedIds[0], model).id;
|
|
57
|
+
if (model.state.inputRef.current.value !== value) {
|
|
58
|
+
// Programmatically dispatch an onChange once items are loaded. This account for when a consumer wants an initial selected item and they're loading them from a server.
|
|
59
|
+
dispatchInputEvent(model.state.inputRef.current, value);
|
|
62
60
|
}
|
|
63
61
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
62
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
63
|
+
}, [model.state.inputRef, model.state.items.length]);
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
onKeyDown(event: React.KeyboardEvent) {
|
|
67
|
+
// Prevent the keys from being enter in the input
|
|
68
|
+
if (event.key !== 'Tab') {
|
|
69
|
+
event.preventDefault();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Select should open if Spacebar is typed and nothing has been typed AND the menu is hidden
|
|
73
|
+
if (
|
|
74
|
+
event.key === 'Spacebar' ||
|
|
75
|
+
(event.key === ' ' && model.state.visibility === 'hidden' && elemProps?.keySofar === '')
|
|
76
|
+
) {
|
|
77
|
+
model.events.show();
|
|
78
|
+
}
|
|
79
|
+
// if the menu is visible
|
|
80
|
+
if (
|
|
81
|
+
(event.key === 'Spacebar' || event.key === ' ') &&
|
|
82
|
+
model.state.visibility === 'visible'
|
|
83
|
+
) {
|
|
84
|
+
// If key so far is empty, they're done typing, select the item where the cursor is located and hide the menu
|
|
85
|
+
if (elemProps?.keySofar === '') {
|
|
86
|
+
model.events.select({
|
|
87
|
+
id: model.state.cursorId,
|
|
88
|
+
});
|
|
89
|
+
model.events.hide();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
onChange: handleOnChange,
|
|
94
|
+
autoComplete: 'off',
|
|
95
|
+
// When the hidden input is focused, we want to show the focus/hover states of the input that sits below it.
|
|
96
|
+
onFocus() {
|
|
97
|
+
textInputRef.current?.focus();
|
|
98
|
+
},
|
|
99
|
+
textInputProps: {
|
|
100
|
+
ref: textInputRef,
|
|
101
|
+
},
|
|
102
|
+
ref: elementRef,
|
|
103
|
+
|
|
104
|
+
// Account for the case where an initial item is selected when the Select first renders
|
|
105
|
+
defaultValue:
|
|
106
|
+
model.state.selectedIds.length > 0 && model.state.items.length > 0
|
|
107
|
+
? model.navigation.getItem(model.state.selectedIds[0], model).textValue ||
|
|
108
|
+
model.state.value
|
|
109
|
+
: undefined,
|
|
110
|
+
} as const;
|
|
111
|
+
}
|
|
112
|
+
),
|
|
71
113
|
useComboboxKeyboardTypeAhead,
|
|
72
114
|
useComboboxResetCursorToSelected,
|
|
73
115
|
useComboboxMoveCursorToSelected,
|
|
@@ -38,10 +38,10 @@ const StyledTextInput = styled('input')<
|
|
|
38
38
|
'&::placeholder': {
|
|
39
39
|
color: inputColors.placeholder,
|
|
40
40
|
},
|
|
41
|
-
'&:hover': {
|
|
41
|
+
'&:hover, &.hover': {
|
|
42
42
|
borderColor: inputColors.hoverBorder,
|
|
43
43
|
},
|
|
44
|
-
'&:focus:not([disabled])': {
|
|
44
|
+
'&:focus-visible:not([disabled]), &.focus:not([disabled]), &:focus:not([disabled])': {
|
|
45
45
|
borderColor: inputColors.focusBorder,
|
|
46
46
|
boxShadow: `inset 0 0 0 1px ${inputColors.focusBorder}`,
|
|
47
47
|
outline: 'none',
|
|
@@ -68,7 +68,7 @@ const StyledTextInput = styled('input')<
|
|
|
68
68
|
},
|
|
69
69
|
({theme, error}) => {
|
|
70
70
|
return {
|
|
71
|
-
'&:focus:not([disabled])': {
|
|
71
|
+
'&:focus-visible:not([disabled]), &.focus:not([disabled])': {
|
|
72
72
|
borderColor: theme.canvas.palette.common.focusOutline,
|
|
73
73
|
boxShadow: `inset 0 0 0 1px ${theme.canvas.palette.common.focusOutline}`,
|
|
74
74
|
outline: 'none',
|