@khanacademy/wonder-blocks-search-field 1.0.1 → 1.0.2
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
CHANGED
package/dist/es/index.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import _extends from '@babel/runtime/helpers/extends';
|
|
2
2
|
import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/objectWithoutPropertiesLoose';
|
|
3
3
|
import * as React from 'react';
|
|
4
|
-
import * as ReactDOM from 'react-dom';
|
|
5
4
|
import { StyleSheet } from 'aphrodite';
|
|
6
5
|
import { styles as styles$1 } from '@khanacademy/wonder-blocks-typography';
|
|
7
|
-
import { View } from '@khanacademy/wonder-blocks-core';
|
|
6
|
+
import { IDProvider, View } from '@khanacademy/wonder-blocks-core';
|
|
8
7
|
import IconButton from '@khanacademy/wonder-blocks-icon-button';
|
|
9
8
|
import { TextField } from '@khanacademy/wonder-blocks-form';
|
|
10
9
|
import Icon, { icons } from '@khanacademy/wonder-blocks-icon';
|
|
@@ -54,15 +53,21 @@ const SearchField = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
54
53
|
onFocus,
|
|
55
54
|
onBlur
|
|
56
55
|
} = props,
|
|
57
|
-
otherProps = _objectWithoutPropertiesLoose(props, _excluded);
|
|
56
|
+
otherProps = _objectWithoutPropertiesLoose(props, _excluded); // We can't just use ref.current to clear the input because ref isn't
|
|
57
|
+
// always being passed in, so we use an innerRef to allow the
|
|
58
|
+
// handleClear() function to focus on the input element ref.
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
const innerRef = React.useRef(null);
|
|
58
62
|
|
|
59
63
|
const handleClear = () => {
|
|
64
|
+
var _innerRef$current;
|
|
65
|
+
|
|
60
66
|
// Empty the search text.
|
|
61
67
|
onChange(""); // Focus back on the text field since the clear button disappears after
|
|
62
68
|
// the field is cleared.
|
|
63
69
|
|
|
64
|
-
|
|
65
|
-
currentField.focus();
|
|
70
|
+
innerRef == null ? void 0 : (_innerRef$current = innerRef.current) == null ? void 0 : _innerRef$current.focus();
|
|
66
71
|
};
|
|
67
72
|
|
|
68
73
|
const maybeRenderClearIconButton = () => {
|
|
@@ -79,7 +84,10 @@ const SearchField = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
79
84
|
});
|
|
80
85
|
};
|
|
81
86
|
|
|
82
|
-
return /*#__PURE__*/React.createElement(
|
|
87
|
+
return /*#__PURE__*/React.createElement(IDProvider, {
|
|
88
|
+
id: id,
|
|
89
|
+
scope: "search-field"
|
|
90
|
+
}, uniqueId => /*#__PURE__*/React.createElement(View, {
|
|
83
91
|
onClick: onClick,
|
|
84
92
|
style: [styles.inputContainer, style]
|
|
85
93
|
}, /*#__PURE__*/React.createElement(Icon, {
|
|
@@ -89,7 +97,7 @@ const SearchField = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
89
97
|
style: styles.searchIcon,
|
|
90
98
|
"aria-hidden": "true"
|
|
91
99
|
}), /*#__PURE__*/React.createElement(TextField, _extends({
|
|
92
|
-
id:
|
|
100
|
+
id: `${uniqueId}-field`,
|
|
93
101
|
type: "text",
|
|
94
102
|
disabled: disabled,
|
|
95
103
|
light: light,
|
|
@@ -97,11 +105,20 @@ const SearchField = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
97
105
|
onFocus: onFocus,
|
|
98
106
|
onBlur: onBlur,
|
|
99
107
|
placeholder: placeholder,
|
|
100
|
-
ref:
|
|
108
|
+
ref: node => {
|
|
109
|
+
// We have to set the value of both refs to
|
|
110
|
+
// the HTMLInputElement from TextField.
|
|
111
|
+
if (ref) {
|
|
112
|
+
// $FlowIgnore[prop-missing]
|
|
113
|
+
ref.current = node;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
innerRef.current = node;
|
|
117
|
+
},
|
|
101
118
|
value: value,
|
|
102
119
|
style: [styles.inputStyleReset, styles$1.LabelMedium],
|
|
103
120
|
testId: testId
|
|
104
|
-
}, otherProps)), maybeRenderClearIconButton());
|
|
121
|
+
}, otherProps)), maybeRenderClearIconButton()));
|
|
105
122
|
});
|
|
106
123
|
const styles = StyleSheet.create({
|
|
107
124
|
inputContainer: {
|