@sproutsocial/racine 11.3.0-beta.0 → 11.3.0-beta.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/__flow__/Input/index.js +6 -15
- package/__flow__/Input/index.test.js +16 -41
- package/commonjs/Input/index.js +4 -7
- package/lib/Input/index.js +4 -7
- package/package.json +1 -1
package/__flow__/Input/index.js
CHANGED
|
@@ -45,13 +45,8 @@ type TypeProps = {
|
|
|
45
45
|
/** Used to get a reference to the underlying element */
|
|
46
46
|
innerRef?: React.Ref<"input">,
|
|
47
47
|
onBlur?: (e: SyntheticFocusEvent<HTMLInputElement>) => void,
|
|
48
|
-
onChange?: (
|
|
49
|
-
|
|
50
|
-
| SyntheticInputEvent<HTMLInputElement>
|
|
51
|
-
| SyntheticEvent<HTMLButtonElement>,
|
|
52
|
-
value: string
|
|
53
|
-
) => void,
|
|
54
|
-
/** Called on Input.ClearButton trigger */
|
|
48
|
+
onChange?: (e: SyntheticInputEvent<HTMLInputElement>, value: string) => void,
|
|
49
|
+
/** Called on Input.ClearButton trigger. */
|
|
55
50
|
onClear?: (e: SyntheticEvent<HTMLButtonElement>) => void,
|
|
56
51
|
onFocus?: (e: SyntheticFocusEvent<HTMLInputElement>) => void,
|
|
57
52
|
onKeyDown?: (
|
|
@@ -106,13 +101,8 @@ class Input extends React.Component<TypeProps> {
|
|
|
106
101
|
handleBlur = (e: SyntheticFocusEvent<HTMLInputElement>) =>
|
|
107
102
|
this.props.onBlur?.(e);
|
|
108
103
|
|
|
109
|
-
handleClear = (e: SyntheticEvent<HTMLButtonElement>) =>
|
|
110
|
-
|
|
111
|
-
this.props.onClear(e);
|
|
112
|
-
} else if (this.props.onChange) {
|
|
113
|
-
this.props.onChange(e, "");
|
|
114
|
-
}
|
|
115
|
-
};
|
|
104
|
+
handleClear = (e: SyntheticEvent<HTMLButtonElement>) =>
|
|
105
|
+
this.props.onClear?.(e);
|
|
116
106
|
|
|
117
107
|
handleChange = (e: SyntheticInputEvent<HTMLInputElement>) =>
|
|
118
108
|
this.props.onChange?.(e, e.currentTarget.value);
|
|
@@ -176,8 +166,9 @@ class Input extends React.Component<TypeProps> {
|
|
|
176
166
|
) : (
|
|
177
167
|
elemBefore
|
|
178
168
|
);
|
|
169
|
+
// Do not add a ClearButton if no onClear callback is provided or if an elemAfter prop was passed.
|
|
179
170
|
const elementAfter =
|
|
180
|
-
type === "search" && !elemAfter ? <ClearButton /> : elemAfter;
|
|
171
|
+
type === "search" && onClear && !elemAfter ? <ClearButton /> : elemAfter;
|
|
181
172
|
|
|
182
173
|
return (
|
|
183
174
|
<Container
|
|
@@ -72,16 +72,17 @@ describe("Input", () => {
|
|
|
72
72
|
describe("Input.ClearButton", () => {
|
|
73
73
|
describe("Input type=search", () => {
|
|
74
74
|
it("should render a clear button for search Inputs", () => {
|
|
75
|
-
const {
|
|
75
|
+
const { getByRole } = render(
|
|
76
76
|
<Input
|
|
77
77
|
id="name"
|
|
78
78
|
name="name"
|
|
79
79
|
value="mic"
|
|
80
80
|
type="search"
|
|
81
|
+
onClear={jest.fn()}
|
|
81
82
|
clearButtonLabel="Clear search"
|
|
82
83
|
/>
|
|
83
84
|
);
|
|
84
|
-
expect(
|
|
85
|
+
expect(getByRole("button")).toBeTruthy();
|
|
85
86
|
});
|
|
86
87
|
|
|
87
88
|
it("should not override an elemAfter prop if passed", () => {
|
|
@@ -91,6 +92,7 @@ describe("Input", () => {
|
|
|
91
92
|
name="name"
|
|
92
93
|
value="mic"
|
|
93
94
|
type="search"
|
|
95
|
+
onClear={jest.fn()}
|
|
94
96
|
elemAfter={<Text>After</Text>}
|
|
95
97
|
/>
|
|
96
98
|
);
|
|
@@ -99,42 +101,32 @@ describe("Input", () => {
|
|
|
99
101
|
});
|
|
100
102
|
|
|
101
103
|
it("should use the fallback title if clearButtonLabel is not provided", () => {
|
|
102
|
-
const { getByTitle } = render(
|
|
103
|
-
<Input id="name" name="name" value="mic" type="search" />
|
|
104
|
-
);
|
|
105
|
-
expect(getByTitle("Clear")).toBeTruthy();
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it("should call onClear when clicked", () => {
|
|
109
|
-
const mockOnClear = jest.fn();
|
|
110
104
|
const { getByTitle } = render(
|
|
111
105
|
<Input
|
|
112
106
|
id="name"
|
|
113
107
|
name="name"
|
|
114
108
|
value="mic"
|
|
115
109
|
type="search"
|
|
116
|
-
onClear={
|
|
117
|
-
clearButtonLabel="Clear search"
|
|
110
|
+
onClear={jest.fn()}
|
|
118
111
|
/>
|
|
119
112
|
);
|
|
120
|
-
|
|
121
|
-
expect(mockOnClear).toHaveBeenCalled();
|
|
113
|
+
expect(getByTitle("Clear")).toBeTruthy();
|
|
122
114
|
});
|
|
123
115
|
|
|
124
|
-
it("should call
|
|
125
|
-
const
|
|
126
|
-
const {
|
|
116
|
+
it("should call onClear when clicked", () => {
|
|
117
|
+
const mockOnClear = jest.fn();
|
|
118
|
+
const { getByRole } = render(
|
|
127
119
|
<Input
|
|
128
120
|
id="name"
|
|
129
121
|
name="name"
|
|
130
122
|
value="mic"
|
|
131
123
|
type="search"
|
|
132
|
-
|
|
124
|
+
onClear={mockOnClear}
|
|
133
125
|
clearButtonLabel="Clear search"
|
|
134
126
|
/>
|
|
135
127
|
);
|
|
136
|
-
fireEvent.click(
|
|
137
|
-
expect(
|
|
128
|
+
fireEvent.click(getByRole("button"));
|
|
129
|
+
expect(mockOnClear).toHaveBeenCalled();
|
|
138
130
|
});
|
|
139
131
|
|
|
140
132
|
it("should allow keyboard access to and Space key triggering of the clear button", () => {
|
|
@@ -184,7 +176,7 @@ describe("Input", () => {
|
|
|
184
176
|
|
|
185
177
|
describe("Manual Input.ClearButton usage", () => {
|
|
186
178
|
it("should render a clear button when passed with elemAfter", () => {
|
|
187
|
-
const {
|
|
179
|
+
const { getByRole } = render(
|
|
188
180
|
<Input
|
|
189
181
|
id="name"
|
|
190
182
|
name="name"
|
|
@@ -194,7 +186,7 @@ describe("Input", () => {
|
|
|
194
186
|
clearButtonLabel="Clear search"
|
|
195
187
|
/>
|
|
196
188
|
);
|
|
197
|
-
expect(
|
|
189
|
+
expect(getByRole("button")).toBeTruthy();
|
|
198
190
|
});
|
|
199
191
|
|
|
200
192
|
it("should use the fallback title if clearButtonLabel is not provided", () => {
|
|
@@ -212,7 +204,7 @@ describe("Input", () => {
|
|
|
212
204
|
|
|
213
205
|
it("should call onClear when Input.ClearButton is clicked", () => {
|
|
214
206
|
const mockOnClear = jest.fn();
|
|
215
|
-
const {
|
|
207
|
+
const { getByRole } = render(
|
|
216
208
|
<Input
|
|
217
209
|
id="name"
|
|
218
210
|
name="name"
|
|
@@ -223,27 +215,10 @@ describe("Input", () => {
|
|
|
223
215
|
clearButtonLabel="Clear search"
|
|
224
216
|
/>
|
|
225
217
|
);
|
|
226
|
-
fireEvent.click(
|
|
218
|
+
fireEvent.click(getByRole("button"));
|
|
227
219
|
expect(mockOnClear).toHaveBeenCalled();
|
|
228
220
|
});
|
|
229
221
|
|
|
230
|
-
it("should call onChange when clicked if there is no onClear prop", () => {
|
|
231
|
-
const mockOnChange = jest.fn();
|
|
232
|
-
const { getByTitle } = render(
|
|
233
|
-
<Input
|
|
234
|
-
id="name"
|
|
235
|
-
name="name"
|
|
236
|
-
value="mic"
|
|
237
|
-
type="text"
|
|
238
|
-
elemAfter={<Input.ClearButton />}
|
|
239
|
-
onChange={mockOnChange}
|
|
240
|
-
clearButtonLabel="Clear search"
|
|
241
|
-
/>
|
|
242
|
-
);
|
|
243
|
-
fireEvent.click(getByTitle("Clear search"));
|
|
244
|
-
expect(mockOnChange).toHaveBeenLastCalledWith(expect.anything(), "");
|
|
245
|
-
});
|
|
246
|
-
|
|
247
222
|
it("should allow keyboard access to and Space key triggering of the clear button", () => {
|
|
248
223
|
const mockOnClear = jest.fn();
|
|
249
224
|
const { getByRole } = render(
|
package/commonjs/Input/index.js
CHANGED
|
@@ -59,11 +59,7 @@ var Input = /*#__PURE__*/function (_React$Component) {
|
|
|
59
59
|
};
|
|
60
60
|
|
|
61
61
|
_this.handleClear = function (e) {
|
|
62
|
-
|
|
63
|
-
_this.props.onClear(e);
|
|
64
|
-
} else if (_this.props.onChange) {
|
|
65
|
-
_this.props.onChange(e, "");
|
|
66
|
-
}
|
|
62
|
+
return _this.props.onClear == null ? void 0 : _this.props.onClear(e);
|
|
67
63
|
};
|
|
68
64
|
|
|
69
65
|
_this.handleChange = function (e) {
|
|
@@ -139,8 +135,9 @@ var Input = /*#__PURE__*/function (_React$Component) {
|
|
|
139
135
|
var elementBefore = type === "search" && !elemBefore ? /*#__PURE__*/React.createElement(_Icon.default, {
|
|
140
136
|
name: "search",
|
|
141
137
|
ariaHidden: true
|
|
142
|
-
}) : elemBefore;
|
|
143
|
-
|
|
138
|
+
}) : elemBefore; // Do not add a ClearButton if no onClear callback is provided or if an elemAfter prop was passed.
|
|
139
|
+
|
|
140
|
+
var elementAfter = type === "search" && onClear && !elemAfter ? /*#__PURE__*/React.createElement(ClearButton, null) : elemAfter;
|
|
144
141
|
return /*#__PURE__*/React.createElement(_styles.default, _extends({
|
|
145
142
|
hasBeforeElement: !!elementBefore,
|
|
146
143
|
hasAfterElement: !!elementAfter,
|
package/lib/Input/index.js
CHANGED
|
@@ -44,11 +44,7 @@ var Input = /*#__PURE__*/function (_React$Component) {
|
|
|
44
44
|
};
|
|
45
45
|
|
|
46
46
|
_this.handleClear = function (e) {
|
|
47
|
-
|
|
48
|
-
_this.props.onClear(e);
|
|
49
|
-
} else if (_this.props.onChange) {
|
|
50
|
-
_this.props.onChange(e, "");
|
|
51
|
-
}
|
|
47
|
+
return _this.props.onClear == null ? void 0 : _this.props.onClear(e);
|
|
52
48
|
};
|
|
53
49
|
|
|
54
50
|
_this.handleChange = function (e) {
|
|
@@ -124,8 +120,9 @@ var Input = /*#__PURE__*/function (_React$Component) {
|
|
|
124
120
|
var elementBefore = type === "search" && !elemBefore ? /*#__PURE__*/React.createElement(Icon, {
|
|
125
121
|
name: "search",
|
|
126
122
|
ariaHidden: true
|
|
127
|
-
}) : elemBefore;
|
|
128
|
-
|
|
123
|
+
}) : elemBefore; // Do not add a ClearButton if no onClear callback is provided or if an elemAfter prop was passed.
|
|
124
|
+
|
|
125
|
+
var elementAfter = type === "search" && onClear && !elemAfter ? /*#__PURE__*/React.createElement(ClearButton, null) : elemAfter;
|
|
129
126
|
return /*#__PURE__*/React.createElement(Container, _extends({
|
|
130
127
|
hasBeforeElement: !!elementBefore,
|
|
131
128
|
hasAfterElement: !!elementAfter,
|