@sproutsocial/racine 11.3.0-beta.3 → 11.3.0-text-highlight.1
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/CHANGELOG.md +6 -0
- package/__flow__/Input/index.js +66 -141
- package/__flow__/Input/index.stories.js +0 -65
- package/__flow__/Input/index.test.js +1 -227
- package/__flow__/Input/styles.js +1 -1
- package/__flow__/themes/dark/theme.js +3 -0
- package/__flow__/themes/light/theme.js +3 -0
- package/__flow__/types/theme.colors.flow.js +3 -0
- package/commonjs/Avatar/index.js +4 -7
- package/commonjs/Badge/index.js +1 -3
- package/commonjs/Badge/styles.js +1 -1
- package/commonjs/Banner/index.js +1 -3
- package/commonjs/Banner/styles.js +1 -1
- package/commonjs/Box/styles.js +1 -1
- package/commonjs/Breadcrumb/index.js +2 -5
- package/commonjs/Button/index.js +1 -3
- package/commonjs/Card/index.js +1 -3
- package/commonjs/Card/styles.js +3 -3
- package/commonjs/CharacterCounter/index.js +1 -3
- package/commonjs/CharacterCounter/styles.js +1 -1
- package/commonjs/ChartLegend/index.js +1 -3
- package/commonjs/ChartLegend/styles.js +3 -3
- package/commonjs/Checkbox/index.js +1 -3
- package/commonjs/Checkbox/styles.js +1 -1
- package/commonjs/Collapsible/index.js +2 -5
- package/commonjs/DatePicker/DateRangePicker.js +1 -3
- package/commonjs/DatePicker/SingleDatePicker.js +1 -3
- package/commonjs/DatePicker/StatefulDateRangePicker.js +1 -3
- package/commonjs/DatePicker/StatefulSingleDatePicker.js +1 -3
- package/commonjs/DatePicker/common.js +1 -1
- package/commonjs/DatePicker/styles.js +6 -2
- package/commonjs/Drawer/SlideTransition.js +1 -3
- package/commonjs/Drawer/index.js +4 -9
- package/commonjs/Drawer/styles.js +2 -2
- package/commonjs/EmptyState/index.js +1 -3
- package/commonjs/Fieldset/index.js +3 -7
- package/commonjs/FormField/index.js +1 -3
- package/commonjs/Icon/index.js +2 -5
- package/commonjs/Icon/styles.js +1 -1
- package/commonjs/Image/index.js +1 -3
- package/commonjs/Image/styles.js +1 -1
- package/commonjs/Indicator/index.js +1 -3
- package/commonjs/Input/index.js +31 -103
- package/commonjs/Input/styles.js +3 -3
- package/commonjs/KeyboardKey/index.js +1 -3
- package/commonjs/Label/index.js +2 -4
- package/commonjs/Link/index.js +1 -3
- package/commonjs/Link/styles.js +1 -1
- package/commonjs/Listbox/index.js +4 -7
- package/commonjs/Loader/index.js +1 -3
- package/commonjs/Loader/styles.js +2 -2
- package/commonjs/LoaderButton/index.js +1 -3
- package/commonjs/Menu/constants.js +1 -1
- package/commonjs/Menu/descendants.js +7 -10
- package/commonjs/Menu/hooks.js +1 -1
- package/commonjs/Menu/index.js +16 -22
- package/commonjs/Menu/styles.js +2 -2
- package/commonjs/Message/index.js +1 -3
- package/commonjs/Message/styles.js +1 -1
- package/commonjs/Modal/index.js +3 -7
- package/commonjs/Modal/styles.js +6 -4
- package/commonjs/Numeral/constants.js +1 -1
- package/commonjs/Numeral/index.js +1 -3
- package/commonjs/Numeral/styles.js +3 -3
- package/commonjs/OverflowList/styles.js +1 -1
- package/commonjs/Popout/index.js +3 -7
- package/commonjs/Popout/styles.js +1 -1
- package/commonjs/Radio/index.js +1 -3
- package/commonjs/Radio/styles.js +4 -4
- package/commonjs/SegmentedControl/index.js +2 -5
- package/commonjs/Select/index.js +1 -3
- package/commonjs/Stack/index.js +1 -3
- package/commonjs/Switch/index.js +1 -3
- package/commonjs/Switch/styles.js +1 -1
- package/commonjs/Table/index.js +5 -10
- package/commonjs/TableCell/index.js +1 -3
- package/commonjs/TableHeaderCell/index.js +1 -3
- package/commonjs/TableRowAccordion/index.js +1 -3
- package/commonjs/Tabs/index.js +2 -5
- package/commonjs/Tabs/styles.js +4 -4
- package/commonjs/Text/index.js +1 -3
- package/commonjs/Text/styles.js +1 -1
- package/commonjs/Textarea/index.js +1 -3
- package/commonjs/Toast/index.js +15 -15
- package/commonjs/Toast/styles.js +7 -4
- package/commonjs/ToggleHint/index.js +1 -3
- package/commonjs/Token/index.js +1 -3
- package/commonjs/Token/styles.js +1 -1
- package/commonjs/TokenInput/index.js +1 -3
- package/commonjs/Tooltip/index.js +2 -5
- package/commonjs/Tooltip/styles.js +1 -1
- package/commonjs/VisuallyHidden/index.js +1 -1
- package/commonjs/index.js +1 -1
- package/commonjs/themes/dark/decorative-palettes.js +1 -1
- package/commonjs/themes/dark/theme.js +5 -2
- package/commonjs/themes/light/decorative-palettes.js +1 -1
- package/commonjs/themes/light/theme.js +5 -2
- package/commonjs/utils/hooks.js +2 -3
- package/commonjs/utils/mixins.js +1 -1
- package/commonjs/utils/system-props.js +1 -1
- package/dist/themes/dark/dark.scss +9 -6
- package/dist/themes/light/light.scss +99 -96
- package/lib/Avatar/index.js +4 -7
- package/lib/Badge/index.js +1 -3
- package/lib/Badge/styles.js +1 -1
- package/lib/Banner/index.js +1 -3
- package/lib/Banner/styles.js +1 -1
- package/lib/Box/styles.js +1 -1
- package/lib/Breadcrumb/index.js +2 -5
- package/lib/Button/index.js +1 -3
- package/lib/Card/index.js +1 -3
- package/lib/Card/styles.js +2 -2
- package/lib/CharacterCounter/index.js +1 -3
- package/lib/CharacterCounter/styles.js +1 -1
- package/lib/ChartLegend/index.js +1 -3
- package/lib/ChartLegend/styles.js +3 -3
- package/lib/Checkbox/index.js +1 -3
- package/lib/Collapsible/index.js +2 -5
- package/lib/DatePicker/DateRangePicker.js +1 -3
- package/lib/DatePicker/SingleDatePicker.js +1 -3
- package/lib/DatePicker/StatefulDateRangePicker.js +1 -3
- package/lib/DatePicker/StatefulSingleDatePicker.js +1 -3
- package/lib/DatePicker/styles.js +6 -2
- package/lib/Drawer/SlideTransition.js +1 -3
- package/lib/Drawer/index.js +4 -9
- package/lib/Drawer/styles.js +2 -2
- package/lib/EmptyState/index.js +1 -3
- package/lib/Fieldset/index.js +3 -7
- package/lib/FormField/index.js +1 -3
- package/lib/Icon/index.js +2 -5
- package/lib/Icon/styles.js +1 -1
- package/lib/Image/index.js +1 -3
- package/lib/Image/styles.js +1 -1
- package/lib/Indicator/index.js +1 -3
- package/lib/Input/index.js +30 -96
- package/lib/Input/styles.js +3 -3
- package/lib/KeyboardKey/index.js +1 -3
- package/lib/Label/index.js +2 -4
- package/lib/Link/index.js +1 -3
- package/lib/Link/styles.js +1 -1
- package/lib/Listbox/index.js +3 -6
- package/lib/Loader/index.js +1 -3
- package/lib/Loader/styles.js +2 -2
- package/lib/LoaderButton/index.js +1 -3
- package/lib/Menu/descendants.js +2 -5
- package/lib/Menu/index.js +16 -20
- package/lib/Menu/styles.js +2 -2
- package/lib/Message/index.js +1 -3
- package/lib/Modal/index.js +3 -7
- package/lib/Modal/styles.js +5 -3
- package/lib/Numeral/index.js +1 -3
- package/lib/Numeral/styles.js +2 -2
- package/lib/OverflowList/styles.js +1 -1
- package/lib/Popout/index.js +3 -7
- package/lib/Popout/styles.js +1 -1
- package/lib/Radio/index.js +1 -3
- package/lib/Radio/styles.js +4 -4
- package/lib/SegmentedControl/index.js +2 -5
- package/lib/Select/index.js +1 -3
- package/lib/Stack/index.js +1 -3
- package/lib/Switch/index.js +1 -3
- package/lib/Switch/styles.js +1 -1
- package/lib/Table/index.js +4 -9
- package/lib/TableCell/index.js +1 -3
- package/lib/TableHeaderCell/index.js +1 -3
- package/lib/TableRowAccordion/index.js +1 -3
- package/lib/Tabs/index.js +2 -5
- package/lib/Tabs/styles.js +3 -3
- package/lib/Text/index.js +1 -3
- package/lib/Text/styles.js +1 -1
- package/lib/Textarea/index.js +1 -3
- package/lib/Toast/index.js +14 -14
- package/lib/Toast/styles.js +7 -3
- package/lib/ToggleHint/index.js +1 -3
- package/lib/Token/index.js +1 -3
- package/lib/Token/styles.js +1 -1
- package/lib/TokenInput/index.js +1 -3
- package/lib/Tooltip/index.js +2 -5
- package/lib/Tooltip/styles.js +1 -1
- package/lib/VisuallyHidden/index.js +1 -1
- package/lib/themes/dark/theme.js +4 -1
- package/lib/themes/light/theme.js +4 -1
- package/package.json +1 -1
- package/bin/buildNpm.js +0 -58
package/CHANGELOG.md
CHANGED
package/__flow__/Input/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import Container, { Accessory } from "./styles";
|
|
4
|
-
import Button from "../Button";
|
|
5
|
-
import Icon from "../Icon";
|
|
6
4
|
|
|
7
5
|
type TypeProps = {
|
|
8
6
|
/** ID of the form element, should match the "for" value of the associated label */
|
|
@@ -12,8 +10,6 @@ type TypeProps = {
|
|
|
12
10
|
ariaLabel?: string,
|
|
13
11
|
/** Attribute used to associate other elements that describe the Input, like an error */
|
|
14
12
|
ariaDescribedby?: string,
|
|
15
|
-
/** Label for Input.ClearButton. Required when using <Input type="search"/> or <Input.ClearButton/>. */
|
|
16
|
-
clearButtonLabel?: string,
|
|
17
13
|
/** Placeholder text for when value is undefined or empty */
|
|
18
14
|
placeholder?: string,
|
|
19
15
|
/** Current value of the input */
|
|
@@ -46,8 +42,6 @@ type TypeProps = {
|
|
|
46
42
|
innerRef?: React.Ref<"input">,
|
|
47
43
|
onBlur?: (e: SyntheticFocusEvent<HTMLInputElement>) => void,
|
|
48
44
|
onChange?: (e: SyntheticInputEvent<HTMLInputElement>, value: string) => void,
|
|
49
|
-
/** Called on Input.ClearButton trigger. */
|
|
50
|
-
onClear?: (e: SyntheticEvent<HTMLButtonElement>) => void,
|
|
51
45
|
onFocus?: (e: SyntheticFocusEvent<HTMLInputElement>) => void,
|
|
52
46
|
onKeyDown?: (
|
|
53
47
|
e: SyntheticKeyboardEvent<HTMLInputElement>,
|
|
@@ -60,61 +54,14 @@ type TypeProps = {
|
|
|
60
54
|
onPaste?: (e: SyntheticInputEvent<HTMLInputElement>, value: string) => void,
|
|
61
55
|
size?: "large" | "small" | "default",
|
|
62
56
|
qa?: Object,
|
|
63
|
-
/**
|
|
64
|
-
Controls the styles of the input. Primary is our standard input styles and secondary is a borderless input.
|
|
57
|
+
/**
|
|
58
|
+
Controls the styles of the input. Primary is our standard input styles and secondary is a borderless input.
|
|
65
59
|
Note that this prop should only be used to alter styles and not functionality.
|
|
66
60
|
*/
|
|
67
61
|
appearance?: "primary" | "secondary",
|
|
68
62
|
};
|
|
69
63
|
|
|
70
|
-
|
|
71
|
-
// regardless of whether it is manually included as elemAfter or automatically included for type="search" Inputs.
|
|
72
|
-
type TypeInputContext = $Shape<{
|
|
73
|
-
handleClear: (e: SyntheticEvent<HTMLButtonElement>) => void,
|
|
74
|
-
clearButtonLabel: string,
|
|
75
|
-
hasValue: boolean,
|
|
76
|
-
}>;
|
|
77
|
-
|
|
78
|
-
const InputContext = React.createContext<TypeInputContext>({});
|
|
79
|
-
|
|
80
|
-
const ClearButton = () => {
|
|
81
|
-
const { handleClear, clearButtonLabel, hasValue, size } =
|
|
82
|
-
React.useContext(InputContext);
|
|
83
|
-
|
|
84
|
-
// Hide the button when there is no text to clear.
|
|
85
|
-
if (!hasValue) {
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// Cut down the padding for size small Inputs so that the focus ring won't go outside the bounds of the Input.
|
|
90
|
-
// This adjustment is handled automatically for default and large Inputs via Button's size. There is no "small" Button.
|
|
91
|
-
const py = size === "small" ? 100 : undefined;
|
|
92
|
-
const px = size === "small" ? 200 : undefined;
|
|
93
|
-
const buttonSize = size === "small" ? "default" : size;
|
|
94
|
-
|
|
95
|
-
// Warn if clearButtonLabel is not included, so that the unlocalized fallback will not be mistaken for a proper label.
|
|
96
|
-
if (!clearButtonLabel) {
|
|
97
|
-
console.warn(
|
|
98
|
-
"Warning: clearButtonLabel prop is required when using Input.ClearButton. Please pass a localized label to Input."
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
return (
|
|
102
|
-
<Button onClick={handleClear} size={buttonSize} py={py} px={px}>
|
|
103
|
-
<Icon name="circlex" title={clearButtonLabel || "Clear"} />
|
|
104
|
-
</Button>
|
|
105
|
-
);
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
// Used for positioning elementAfter. This logic will detect if the element is a ClearButton,
|
|
109
|
-
// regardless of whether it was manually passed as elemAfter or automatically added to a search Input.
|
|
110
|
-
const isClearButton = (elem: any) => {
|
|
111
|
-
if (elem?.type) {
|
|
112
|
-
return elem.type.displayName === "Input.ClearButton";
|
|
113
|
-
}
|
|
114
|
-
return false;
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
class Input extends React.Component<TypeProps> {
|
|
64
|
+
export default class Input extends React.Component<TypeProps> {
|
|
118
65
|
static defaultProps = {
|
|
119
66
|
autoFocus: false,
|
|
120
67
|
disabled: false,
|
|
@@ -123,30 +70,41 @@ class Input extends React.Component<TypeProps> {
|
|
|
123
70
|
appearance: "primary",
|
|
124
71
|
};
|
|
125
72
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
handleClear = (e: SyntheticEvent<HTMLButtonElement>) => {
|
|
132
|
-
this.props.onClear?.(e);
|
|
133
|
-
this.props.innerRef?.current?.focus();
|
|
73
|
+
handleBlur = (e: SyntheticFocusEvent<HTMLInputElement>) => {
|
|
74
|
+
if (this.props.onBlur) {
|
|
75
|
+
this.props.onBlur(e);
|
|
76
|
+
}
|
|
134
77
|
};
|
|
135
78
|
|
|
136
|
-
handleChange = (e: SyntheticInputEvent<HTMLInputElement>) =>
|
|
137
|
-
this.props.onChange
|
|
79
|
+
handleChange = (e: SyntheticInputEvent<HTMLInputElement>) => {
|
|
80
|
+
if (this.props.onChange) {
|
|
81
|
+
this.props.onChange(e, e.currentTarget.value);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
138
84
|
|
|
139
|
-
handleFocus = (e: SyntheticFocusEvent<HTMLInputElement>) =>
|
|
140
|
-
this.props.onFocus
|
|
85
|
+
handleFocus = (e: SyntheticFocusEvent<HTMLInputElement>) => {
|
|
86
|
+
if (this.props.onFocus) {
|
|
87
|
+
this.props.onFocus(e);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
141
90
|
|
|
142
|
-
handleKeyDown = (e: SyntheticKeyboardEvent<HTMLInputElement>) =>
|
|
143
|
-
this.props.onKeyDown
|
|
91
|
+
handleKeyDown = (e: SyntheticKeyboardEvent<HTMLInputElement>) => {
|
|
92
|
+
if (this.props.onKeyDown) {
|
|
93
|
+
this.props.onKeyDown(e, e.currentTarget.value);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
144
96
|
|
|
145
|
-
handleKeyUp = (e: SyntheticKeyboardEvent<HTMLInputElement>) =>
|
|
146
|
-
this.props.onKeyUp
|
|
97
|
+
handleKeyUp = (e: SyntheticKeyboardEvent<HTMLInputElement>) => {
|
|
98
|
+
if (this.props.onKeyUp) {
|
|
99
|
+
this.props.onKeyUp(e, e.currentTarget.value);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
147
102
|
|
|
148
|
-
handlePaste = (e: SyntheticInputEvent<HTMLInputElement>) =>
|
|
149
|
-
this.props.onPaste
|
|
103
|
+
handlePaste = (e: SyntheticInputEvent<HTMLInputElement>) => {
|
|
104
|
+
if (this.props.onPaste) {
|
|
105
|
+
this.props.onPaste(e, e.currentTarget.value);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
150
108
|
|
|
151
109
|
render() {
|
|
152
110
|
const {
|
|
@@ -167,11 +125,9 @@ class Input extends React.Component<TypeProps> {
|
|
|
167
125
|
maxLength,
|
|
168
126
|
ariaLabel,
|
|
169
127
|
ariaDescribedby,
|
|
170
|
-
clearButtonLabel,
|
|
171
128
|
innerRef,
|
|
172
129
|
onBlur,
|
|
173
130
|
onChange,
|
|
174
|
-
onClear,
|
|
175
131
|
onFocus,
|
|
176
132
|
onKeyDown,
|
|
177
133
|
onKeyUp,
|
|
@@ -179,89 +135,58 @@ class Input extends React.Component<TypeProps> {
|
|
|
179
135
|
inputProps = {},
|
|
180
136
|
qa = {},
|
|
181
137
|
appearance,
|
|
182
|
-
size,
|
|
183
138
|
...rest
|
|
184
139
|
} = this.props;
|
|
185
140
|
|
|
186
|
-
// Convert autoComplete from a boolean prop to a string value.
|
|
187
141
|
let autoCompleteValue = undefined;
|
|
188
142
|
if (autoComplete !== undefined) {
|
|
189
143
|
autoCompleteValue = autoComplete ? "on" : "off";
|
|
190
144
|
}
|
|
191
145
|
|
|
192
|
-
// Add default elemBefore and elemAfter elements if type is search.
|
|
193
|
-
const elementBefore =
|
|
194
|
-
type === "search" && !elemBefore ? (
|
|
195
|
-
<Icon name="search" ariaHidden color="icon.base" />
|
|
196
|
-
) : (
|
|
197
|
-
elemBefore
|
|
198
|
-
);
|
|
199
|
-
// Do not add a ClearButton if no onClear callback is provided or if an elemAfter prop was passed.
|
|
200
|
-
const elementAfter =
|
|
201
|
-
type === "search" && onClear && !elemAfter ? <ClearButton /> : elemAfter;
|
|
202
|
-
|
|
203
146
|
return (
|
|
204
147
|
<Container
|
|
205
|
-
hasBeforeElement={!!
|
|
206
|
-
hasAfterElement={!!
|
|
148
|
+
hasBeforeElement={!!elemBefore}
|
|
149
|
+
hasAfterElement={!!elemAfter}
|
|
207
150
|
disabled={disabled}
|
|
208
151
|
invalid={!!isInvalid}
|
|
209
152
|
warning={hasWarning}
|
|
210
153
|
appearance={appearance}
|
|
211
|
-
size={size}
|
|
212
154
|
// $FlowIssue - upgrade v0.112.0
|
|
213
155
|
{...rest}
|
|
214
156
|
>
|
|
215
|
-
<
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
{
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
data-qa-input={name || ""}
|
|
248
|
-
data-qa-input-isdisabled={disabled === true}
|
|
249
|
-
data-qa-input-isrequired={required === true}
|
|
250
|
-
{...qa}
|
|
251
|
-
{...inputProps}
|
|
252
|
-
/>
|
|
253
|
-
|
|
254
|
-
{elementAfter && (
|
|
255
|
-
<Accessory after isClearButton={isClearButton(elementAfter)}>
|
|
256
|
-
{elementAfter}
|
|
257
|
-
</Accessory>
|
|
258
|
-
)}
|
|
259
|
-
</InputContext.Provider>
|
|
157
|
+
{elemBefore && <Accessory before>{elemBefore}</Accessory>}
|
|
158
|
+
|
|
159
|
+
<input
|
|
160
|
+
aria-invalid={!!isInvalid}
|
|
161
|
+
aria-label={ariaLabel}
|
|
162
|
+
aria-describedby={ariaDescribedby}
|
|
163
|
+
autoComplete={autoCompleteValue}
|
|
164
|
+
autoFocus={autoFocus}
|
|
165
|
+
disabled={disabled}
|
|
166
|
+
readOnly={readOnly}
|
|
167
|
+
id={id}
|
|
168
|
+
name={name}
|
|
169
|
+
placeholder={placeholder}
|
|
170
|
+
type={type}
|
|
171
|
+
required={required}
|
|
172
|
+
value={value}
|
|
173
|
+
maxLength={maxLength}
|
|
174
|
+
onBlur={this.handleBlur}
|
|
175
|
+
onChange={this.handleChange}
|
|
176
|
+
onFocus={this.handleFocus}
|
|
177
|
+
onKeyDown={this.handleKeyDown}
|
|
178
|
+
onKeyUp={this.handleKeyUp}
|
|
179
|
+
onPaste={this.handlePaste}
|
|
180
|
+
ref={innerRef}
|
|
181
|
+
data-qa-input={name || ""}
|
|
182
|
+
data-qa-input-isdisabled={disabled === true}
|
|
183
|
+
data-qa-input-isrequired={required === true}
|
|
184
|
+
{...qa}
|
|
185
|
+
{...inputProps}
|
|
186
|
+
/>
|
|
187
|
+
|
|
188
|
+
{elemAfter && <Accessory after>{elemAfter}</Accessory>}
|
|
260
189
|
</Container>
|
|
261
190
|
);
|
|
262
191
|
}
|
|
263
192
|
}
|
|
264
|
-
|
|
265
|
-
Input.ClearButton.displayName = "Input.ClearButton";
|
|
266
|
-
|
|
267
|
-
export default Input;
|
|
@@ -141,71 +141,6 @@ leftAndRightIcons.story = {
|
|
|
141
141
|
name: "Left and right icons",
|
|
142
142
|
};
|
|
143
143
|
|
|
144
|
-
export const searchInput = () => (
|
|
145
|
-
<Input
|
|
146
|
-
type="search"
|
|
147
|
-
placeholder={text("placeholder", "Please enter a value...")}
|
|
148
|
-
value={text("value", "val")}
|
|
149
|
-
onClear={() => window.alert("Cleared!")}
|
|
150
|
-
clearButtonLabel={text("clearButtonLabel", "Clear search")}
|
|
151
|
-
ariaLabel={text("ariaLabel", "Descriptive label goes here")}
|
|
152
|
-
/>
|
|
153
|
-
);
|
|
154
|
-
|
|
155
|
-
searchInput.story = {
|
|
156
|
-
name: "Search Input",
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
export const smallSearchInput = () => (
|
|
160
|
-
<Input
|
|
161
|
-
type="search"
|
|
162
|
-
size="small"
|
|
163
|
-
placeholder={text("placeholder", "Please enter a value...")}
|
|
164
|
-
value={text("value", "val")}
|
|
165
|
-
onClear={() => window.alert("Cleared!")}
|
|
166
|
-
clearButtonLabel={text("clearButtonLabel", "Clear search")}
|
|
167
|
-
ariaLabel={text("ariaLabel", "Descriptive label goes here")}
|
|
168
|
-
/>
|
|
169
|
-
);
|
|
170
|
-
|
|
171
|
-
smallSearchInput.story = {
|
|
172
|
-
name: "Small Search Input",
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
export const largeSearchInput = () => (
|
|
176
|
-
<Input
|
|
177
|
-
type="search"
|
|
178
|
-
size="large"
|
|
179
|
-
placeholder={text("placeholder", "Please enter a value...")}
|
|
180
|
-
value={text("value", "val")}
|
|
181
|
-
onClear={() => window.alert("Cleared!")}
|
|
182
|
-
clearButtonLabel={text("clearButtonLabel", "Clear search")}
|
|
183
|
-
ariaLabel={text("ariaLabel", "Descriptive label goes here")}
|
|
184
|
-
/>
|
|
185
|
-
);
|
|
186
|
-
|
|
187
|
-
largeSearchInput.story = {
|
|
188
|
-
name: "Large Search Input",
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
export const nonSearchClearButtonInput = () => {
|
|
192
|
-
return (
|
|
193
|
-
<Input
|
|
194
|
-
type="text"
|
|
195
|
-
placeholder={text("placeholder", "Please enter a value...")}
|
|
196
|
-
value={text("value", "val")}
|
|
197
|
-
onClear={() => window.alert("Cleared!")}
|
|
198
|
-
ariaLabel={text("ariaLabel", "Descriptive label goes here")}
|
|
199
|
-
clearButtonLabel={text("clearButtonLabel", "Clear text")}
|
|
200
|
-
elemAfter={<Input.ClearButton />}
|
|
201
|
-
/>
|
|
202
|
-
);
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
nonSearchClearButtonInput.story = {
|
|
206
|
-
name: "Manual Input.ClearButton usage",
|
|
207
|
-
};
|
|
208
|
-
|
|
209
144
|
export const autofocus = () => (
|
|
210
145
|
<Input
|
|
211
146
|
autoFocus
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import "jest-styled-components";
|
|
3
|
-
import { render, fireEvent
|
|
3
|
+
import { render, fireEvent } from "../utils/react-testing-library";
|
|
4
4
|
import Input from "./";
|
|
5
5
|
import Text from "../Text";
|
|
6
6
|
|
|
@@ -69,232 +69,6 @@ describe("Input", () => {
|
|
|
69
69
|
expect(getByText("After")).toBeTruthy();
|
|
70
70
|
});
|
|
71
71
|
|
|
72
|
-
describe("Input.ClearButton", () => {
|
|
73
|
-
describe("Input type=search", () => {
|
|
74
|
-
it("should render a clear button for search Inputs", () => {
|
|
75
|
-
const { getByRole } = render(
|
|
76
|
-
<Input
|
|
77
|
-
id="name"
|
|
78
|
-
name="name"
|
|
79
|
-
value="mic"
|
|
80
|
-
type="search"
|
|
81
|
-
onClear={jest.fn()}
|
|
82
|
-
clearButtonLabel="Clear search"
|
|
83
|
-
/>
|
|
84
|
-
);
|
|
85
|
-
expect(getByRole("button")).toBeTruthy();
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it("should not render a clear button for search Inputs if there is no text", () => {
|
|
89
|
-
const { queryByRole } = render(
|
|
90
|
-
<Input
|
|
91
|
-
id="name"
|
|
92
|
-
name="name"
|
|
93
|
-
value=""
|
|
94
|
-
type="search"
|
|
95
|
-
onClear={jest.fn()}
|
|
96
|
-
clearButtonLabel="Clear search"
|
|
97
|
-
/>
|
|
98
|
-
);
|
|
99
|
-
expect(queryByRole("button")).toBeFalsy();
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it("should not override an elemAfter prop if passed", () => {
|
|
103
|
-
const { getByText, queryByTitle } = render(
|
|
104
|
-
<Input
|
|
105
|
-
id="name"
|
|
106
|
-
name="name"
|
|
107
|
-
value="mic"
|
|
108
|
-
type="search"
|
|
109
|
-
onClear={jest.fn()}
|
|
110
|
-
elemAfter={<Text>After</Text>}
|
|
111
|
-
/>
|
|
112
|
-
);
|
|
113
|
-
expect(getByText("After")).toBeTruthy();
|
|
114
|
-
expect(queryByTitle("Clear")).not.toBeInTheDocument();
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it("should use the fallback title if clearButtonLabel is not provided", () => {
|
|
118
|
-
const { getByTitle } = render(
|
|
119
|
-
<Input
|
|
120
|
-
id="name"
|
|
121
|
-
name="name"
|
|
122
|
-
value="mic"
|
|
123
|
-
type="search"
|
|
124
|
-
onClear={jest.fn()}
|
|
125
|
-
/>
|
|
126
|
-
);
|
|
127
|
-
expect(getByTitle("Clear")).toBeTruthy();
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it("should call onClear when clicked", () => {
|
|
131
|
-
const mockOnClear = jest.fn();
|
|
132
|
-
const { getByRole } = render(
|
|
133
|
-
<Input
|
|
134
|
-
id="name"
|
|
135
|
-
name="name"
|
|
136
|
-
value="mic"
|
|
137
|
-
type="search"
|
|
138
|
-
onClear={mockOnClear}
|
|
139
|
-
clearButtonLabel="Clear search"
|
|
140
|
-
/>
|
|
141
|
-
);
|
|
142
|
-
fireEvent.click(getByRole("button"));
|
|
143
|
-
expect(mockOnClear).toHaveBeenCalled();
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it("should allow keyboard access to and Space key triggering of the clear button", () => {
|
|
147
|
-
const mockOnClear = jest.fn();
|
|
148
|
-
const { getByRole } = render(
|
|
149
|
-
<Input
|
|
150
|
-
id="name"
|
|
151
|
-
name="name"
|
|
152
|
-
value="mic"
|
|
153
|
-
type="search"
|
|
154
|
-
onClear={mockOnClear}
|
|
155
|
-
clearButtonLabel="Clear search"
|
|
156
|
-
/>
|
|
157
|
-
);
|
|
158
|
-
const input = getByRole("searchbox");
|
|
159
|
-
const button = getByRole("button");
|
|
160
|
-
userEvent.tab();
|
|
161
|
-
expect(input).toHaveFocus();
|
|
162
|
-
userEvent.tab();
|
|
163
|
-
expect(button).toHaveFocus();
|
|
164
|
-
userEvent.keyboard("{space}");
|
|
165
|
-
expect(mockOnClear).toHaveBeenCalled();
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it("should allow keyboard access to and Enter key triggering of the clear button", () => {
|
|
169
|
-
const mockOnClear = jest.fn();
|
|
170
|
-
const { getByRole } = render(
|
|
171
|
-
<Input
|
|
172
|
-
id="name"
|
|
173
|
-
name="name"
|
|
174
|
-
value="mic"
|
|
175
|
-
type="search"
|
|
176
|
-
onClear={mockOnClear}
|
|
177
|
-
clearButtonLabel="Clear search"
|
|
178
|
-
/>
|
|
179
|
-
);
|
|
180
|
-
const input = getByRole("searchbox");
|
|
181
|
-
const button = getByRole("button");
|
|
182
|
-
userEvent.tab();
|
|
183
|
-
expect(input).toHaveFocus();
|
|
184
|
-
userEvent.tab();
|
|
185
|
-
expect(button).toHaveFocus();
|
|
186
|
-
userEvent.keyboard("{enter}");
|
|
187
|
-
expect(mockOnClear).toHaveBeenCalled();
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
describe("Manual Input.ClearButton usage", () => {
|
|
192
|
-
it("should render a clear button when passed with elemAfter", () => {
|
|
193
|
-
const { getByRole } = render(
|
|
194
|
-
<Input
|
|
195
|
-
id="name"
|
|
196
|
-
name="name"
|
|
197
|
-
value="mic"
|
|
198
|
-
type="text"
|
|
199
|
-
elemAfter={<Input.ClearButton />}
|
|
200
|
-
clearButtonLabel="Clear search"
|
|
201
|
-
/>
|
|
202
|
-
);
|
|
203
|
-
expect(getByRole("button")).toBeTruthy();
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
it("should not render a clear button if there is no text", () => {
|
|
207
|
-
const { queryByRole } = render(
|
|
208
|
-
<Input
|
|
209
|
-
id="name"
|
|
210
|
-
name="name"
|
|
211
|
-
value=""
|
|
212
|
-
type="text"
|
|
213
|
-
elemAfter={<Input.ClearButton />}
|
|
214
|
-
clearButtonLabel="Clear search"
|
|
215
|
-
/>
|
|
216
|
-
);
|
|
217
|
-
expect(queryByRole("button")).toBeFalsy();
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
it("should use the fallback title if clearButtonLabel is not provided", () => {
|
|
221
|
-
const { getByTitle } = render(
|
|
222
|
-
<Input
|
|
223
|
-
id="name"
|
|
224
|
-
name="name"
|
|
225
|
-
value="mic"
|
|
226
|
-
type="text"
|
|
227
|
-
elemAfter={<Input.ClearButton />}
|
|
228
|
-
/>
|
|
229
|
-
);
|
|
230
|
-
expect(getByTitle("Clear")).toBeTruthy();
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
it("should call onClear when Input.ClearButton is clicked", () => {
|
|
234
|
-
const mockOnClear = jest.fn();
|
|
235
|
-
const { getByRole } = render(
|
|
236
|
-
<Input
|
|
237
|
-
id="name"
|
|
238
|
-
name="name"
|
|
239
|
-
value="mic"
|
|
240
|
-
type="text"
|
|
241
|
-
elemAfter={<Input.ClearButton />}
|
|
242
|
-
onClear={mockOnClear}
|
|
243
|
-
clearButtonLabel="Clear search"
|
|
244
|
-
/>
|
|
245
|
-
);
|
|
246
|
-
fireEvent.click(getByRole("button"));
|
|
247
|
-
expect(mockOnClear).toHaveBeenCalled();
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
it("should allow keyboard access to and Space key triggering of the clear button", () => {
|
|
251
|
-
const mockOnClear = jest.fn();
|
|
252
|
-
const { getByRole } = render(
|
|
253
|
-
<Input
|
|
254
|
-
id="name"
|
|
255
|
-
name="name"
|
|
256
|
-
value="mic"
|
|
257
|
-
type="text"
|
|
258
|
-
elemAfter={<Input.ClearButton />}
|
|
259
|
-
onClear={mockOnClear}
|
|
260
|
-
clearButtonLabel="Clear search"
|
|
261
|
-
/>
|
|
262
|
-
);
|
|
263
|
-
const input = getByRole("textbox");
|
|
264
|
-
const button = getByRole("button");
|
|
265
|
-
userEvent.tab();
|
|
266
|
-
expect(input).toHaveFocus();
|
|
267
|
-
userEvent.tab();
|
|
268
|
-
expect(button).toHaveFocus();
|
|
269
|
-
userEvent.keyboard("{space}");
|
|
270
|
-
expect(mockOnClear).toHaveBeenCalled();
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
it("should allow keyboard access to and Enter key triggering of the clear button", () => {
|
|
274
|
-
const mockOnClear = jest.fn();
|
|
275
|
-
const { getByRole } = render(
|
|
276
|
-
<Input
|
|
277
|
-
id="name"
|
|
278
|
-
name="name"
|
|
279
|
-
value="mic"
|
|
280
|
-
type="text"
|
|
281
|
-
elemAfter={<Input.ClearButton />}
|
|
282
|
-
onClear={mockOnClear}
|
|
283
|
-
clearButtonLabel="Clear search"
|
|
284
|
-
/>
|
|
285
|
-
);
|
|
286
|
-
const input = getByRole("textbox");
|
|
287
|
-
const button = getByRole("button");
|
|
288
|
-
userEvent.tab();
|
|
289
|
-
expect(input).toHaveFocus();
|
|
290
|
-
userEvent.tab();
|
|
291
|
-
expect(button).toHaveFocus();
|
|
292
|
-
userEvent.keyboard("{enter}");
|
|
293
|
-
expect(mockOnClear).toHaveBeenCalled();
|
|
294
|
-
});
|
|
295
|
-
});
|
|
296
|
-
});
|
|
297
|
-
|
|
298
72
|
describe("autoComplete prop", () => {
|
|
299
73
|
it("should not have autoComplete attribute when passed prop is not passed", () => {
|
|
300
74
|
const { getByDataQaLabel } = render(<Input id="name" name="name" />);
|
package/__flow__/Input/styles.js
CHANGED