@instructure/ui-simple-select 8.25.1-snapshot-10 → 8.25.1-snapshot-13
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 +1 -1
- package/es/SimpleSelect/Group/index.js +5 -6
- package/es/SimpleSelect/Option/index.js +7 -8
- package/es/SimpleSelect/index.js +139 -139
- package/lib/SimpleSelect/Group/index.js +5 -6
- package/lib/SimpleSelect/Option/index.js +7 -8
- package/lib/SimpleSelect/index.js +140 -140
- package/package.json +14 -14
package/CHANGELOG.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
5
5
|
|
6
|
-
## [8.25.1-snapshot-
|
6
|
+
## [8.25.1-snapshot-13](https://github.com/instructure/instructure-ui/compare/v8.25.0...v8.25.1-snapshot-13) (2022-06-22)
|
7
7
|
|
8
8
|
**Note:** Version bump only for package @instructure/ui-simple-select
|
9
9
|
|
@@ -32,13 +32,7 @@ id: SimpleSelect.Group
|
|
32
32
|
**/
|
33
33
|
|
34
34
|
class Group extends Component {
|
35
|
-
static displayName = "Group";
|
36
|
-
static componentId = 'SimpleSelect.Group';
|
37
|
-
static allowedProps = allowedProps;
|
38
|
-
static propTypes = propTypes;
|
39
|
-
static defaultProps = {};
|
40
35
|
/* istanbul ignore next */
|
41
|
-
|
42
36
|
render() {
|
43
37
|
// this component is only used for prop validation. Select.Group children
|
44
38
|
// are parsed in Select and rendered as Options components
|
@@ -47,5 +41,10 @@ class Group extends Component {
|
|
47
41
|
|
48
42
|
}
|
49
43
|
|
44
|
+
Group.displayName = "Group";
|
45
|
+
Group.componentId = 'SimpleSelect.Group';
|
46
|
+
Group.allowedProps = allowedProps;
|
47
|
+
Group.propTypes = propTypes;
|
48
|
+
Group.defaultProps = {};
|
50
49
|
export default Group;
|
51
50
|
export { Group };
|
@@ -32,15 +32,7 @@ id: SimpleSelect.Option
|
|
32
32
|
**/
|
33
33
|
|
34
34
|
class Option extends Component {
|
35
|
-
static displayName = "Option";
|
36
|
-
static componentId = 'SimpleSelect.Option';
|
37
|
-
static allowedProps = allowedProps;
|
38
|
-
static propTypes = propTypes;
|
39
|
-
static defaultProps = {
|
40
|
-
isDisabled: false
|
41
|
-
};
|
42
35
|
/* istanbul ignore next */
|
43
|
-
|
44
36
|
render() {
|
45
37
|
// this component is only used for prop validation. SimpleSelect.Option children
|
46
38
|
// are parsed in Select and rendered as Options.Item components
|
@@ -49,5 +41,12 @@ class Option extends Component {
|
|
49
41
|
|
50
42
|
}
|
51
43
|
|
44
|
+
Option.displayName = "Option";
|
45
|
+
Option.componentId = 'SimpleSelect.Option';
|
46
|
+
Option.allowedProps = allowedProps;
|
47
|
+
Option.propTypes = propTypes;
|
48
|
+
Option.defaultProps = {
|
49
|
+
isDisabled: false
|
50
|
+
};
|
52
51
|
export default Option;
|
53
52
|
export { Option };
|
package/es/SimpleSelect/index.js
CHANGED
@@ -3,7 +3,7 @@ const _excluded = ["id", "value", "children", "renderBeforeLabel", "renderAfterL
|
|
3
3
|
_excluded2 = ["id", "renderLabel", "children"],
|
4
4
|
_excluded3 = ["renderLabel", "value", "defaultValue", "id", "size", "assistiveText", "placeholder", "interaction", "isRequired", "isInline", "width", "optionsMaxWidth", "optionsMaxHeight", "visibleOptionsCount", "messages", "placement", "constrain", "mountNode", "inputRef", "listRef", "renderEmptyOption", "renderBeforeInput", "renderAfterInput", "onFocus", "onBlur", "onShowOptions", "onHideOptions", "children"];
|
5
5
|
|
6
|
-
var _dec, _dec2, _class;
|
6
|
+
var _dec, _dec2, _class, _class2;
|
7
7
|
|
8
8
|
/*
|
9
9
|
* The MIT License (MIT)
|
@@ -43,33 +43,140 @@ tags: form, field, dropdown
|
|
43
43
|
---
|
44
44
|
@tsProps
|
45
45
|
**/
|
46
|
-
let SimpleSelect = (_dec = withDeterministicId(), _dec2 = testable(), _dec(_class = _dec2(_class = class SimpleSelect extends Component {
|
47
|
-
static displayName = "SimpleSelect";
|
48
|
-
static componentId = 'SimpleSelect';
|
49
|
-
static Option = Option;
|
50
|
-
static Group = Group;
|
51
|
-
static allowedProps = allowedProps;
|
52
|
-
static propTypes = propTypes;
|
53
|
-
static defaultProps = {
|
54
|
-
size: 'medium',
|
55
|
-
isRequired: false,
|
56
|
-
isInline: false,
|
57
|
-
visibleOptionsCount: 8,
|
58
|
-
placement: 'bottom stretch',
|
59
|
-
constrain: 'window',
|
60
|
-
renderEmptyOption: '---'
|
61
|
-
};
|
62
|
-
ref = null;
|
63
|
-
_emptyOptionId;
|
64
|
-
|
46
|
+
let SimpleSelect = (_dec = withDeterministicId(), _dec2 = testable(), _dec(_class = _dec2(_class = (_class2 = class SimpleSelect extends Component {
|
65
47
|
constructor(props) {
|
66
48
|
super(props);
|
67
|
-
|
49
|
+
this.ref = null;
|
50
|
+
this._emptyOptionId = void 0;
|
51
|
+
|
52
|
+
this.getOption = (field, value) => {
|
53
|
+
const children = Children.toArray(this.props.children);
|
54
|
+
let match;
|
55
|
+
|
56
|
+
for (let i = 0; i < children.length; ++i) {
|
57
|
+
const child = children[i];
|
58
|
+
|
59
|
+
if (matchComponentTypes(child, [Option])) {
|
60
|
+
if (child.props[field] === value) {
|
61
|
+
match = child;
|
62
|
+
}
|
63
|
+
} else if (matchComponentTypes(child, [Group])) {
|
64
|
+
const groupChildren = Children.toArray(child.props.children);
|
65
|
+
|
66
|
+
for (let j = 0; j < groupChildren.length; ++j) {
|
67
|
+
const groupChild = groupChildren[j];
|
68
|
+
|
69
|
+
if (groupChild.props[field] === value) {
|
70
|
+
match = groupChild;
|
71
|
+
break;
|
72
|
+
}
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
if (match) break;
|
77
|
+
}
|
78
|
+
|
79
|
+
return match;
|
80
|
+
};
|
81
|
+
|
82
|
+
this.handleRef = node => {
|
83
|
+
this.ref = node;
|
84
|
+
};
|
85
|
+
|
86
|
+
this.handleBlur = event => {
|
87
|
+
this.setState({
|
88
|
+
highlightedOptionId: void 0
|
89
|
+
});
|
90
|
+
|
91
|
+
if (typeof this.props.onBlur === 'function') {
|
92
|
+
this.props.onBlur(event);
|
93
|
+
}
|
94
|
+
};
|
95
|
+
|
96
|
+
this.handleShowOptions = event => {
|
97
|
+
this.setState({
|
98
|
+
isShowingOptions: true
|
99
|
+
});
|
100
|
+
|
101
|
+
if (typeof this.props.onShowOptions === 'function') {
|
102
|
+
this.props.onShowOptions(event);
|
103
|
+
}
|
104
|
+
};
|
105
|
+
|
106
|
+
this.handleHideOptions = event => {
|
107
|
+
this.setState(state => {
|
108
|
+
const option = this.getOption('id', state.selectedOptionId);
|
109
|
+
return {
|
110
|
+
isShowingOptions: false,
|
111
|
+
highlightedOptionId: void 0,
|
112
|
+
inputValue: option ? option.props.children : ''
|
113
|
+
};
|
114
|
+
});
|
115
|
+
|
116
|
+
if (typeof this.props.onHideOptions === 'function') {
|
117
|
+
this.props.onHideOptions(event);
|
118
|
+
}
|
119
|
+
};
|
120
|
+
|
121
|
+
this.handleHighlightOption = (event, _ref) => {
|
122
|
+
let id = _ref.id;
|
123
|
+
if (id === this._emptyOptionId) return;
|
124
|
+
const option = this.getOption('id', id);
|
125
|
+
const label = option === null || option === void 0 ? void 0 : option.props.children;
|
126
|
+
const inputValue = event.type === 'keydown' ? label : this.state.inputValue;
|
127
|
+
this.setState({
|
128
|
+
highlightedOptionId: id,
|
129
|
+
inputValue
|
130
|
+
});
|
131
|
+
};
|
132
|
+
|
133
|
+
this.handleSelectOption = (event, _ref2) => {
|
134
|
+
let id = _ref2.id;
|
135
|
+
|
136
|
+
if (id === this._emptyOptionId) {
|
137
|
+
// selected option is the empty option
|
138
|
+
this.setState({
|
139
|
+
isShowingOptions: false
|
140
|
+
});
|
141
|
+
return;
|
142
|
+
}
|
143
|
+
|
144
|
+
const option = this.getOption('id', id);
|
145
|
+
const value = option && option.props.value;
|
146
|
+
|
147
|
+
if (this.isControlled) {
|
148
|
+
this.setState({
|
149
|
+
isShowingOptions: false
|
150
|
+
});
|
151
|
+
} else {
|
152
|
+
this.setState(state => ({
|
153
|
+
isShowingOptions: false,
|
154
|
+
selectedOptionId: id,
|
155
|
+
inputValue: option ? option.props.children : state.inputValue
|
156
|
+
}));
|
157
|
+
} // fire onChange if selected option changed
|
158
|
+
|
159
|
+
|
160
|
+
if (option && typeof this.props.onChange === 'function') {
|
161
|
+
this.props.onChange(event, {
|
162
|
+
value,
|
163
|
+
id
|
164
|
+
});
|
165
|
+
} // hide options list whenever selection is made
|
166
|
+
|
167
|
+
|
168
|
+
if (typeof this.props.onHideOptions === 'function') {
|
169
|
+
this.props.onHideOptions(event);
|
170
|
+
}
|
171
|
+
};
|
172
|
+
|
173
|
+
const _option = this.getInitialOption(props);
|
174
|
+
|
68
175
|
this.state = {
|
69
|
-
inputValue:
|
176
|
+
inputValue: _option ? _option.props.children : '',
|
70
177
|
isShowingOptions: false,
|
71
178
|
highlightedOptionId: void 0,
|
72
|
-
selectedOptionId:
|
179
|
+
selectedOptionId: _option ? _option.props.id : void 0
|
73
180
|
};
|
74
181
|
this._emptyOptionId = props.deterministicId('Select-EmptyOption');
|
75
182
|
}
|
@@ -157,121 +264,6 @@ let SimpleSelect = (_dec = withDeterministicId(), _dec2 = testable(), _dec(_clas
|
|
157
264
|
return match;
|
158
265
|
}
|
159
266
|
|
160
|
-
getOption = (field, value) => {
|
161
|
-
const children = Children.toArray(this.props.children);
|
162
|
-
let match;
|
163
|
-
|
164
|
-
for (let i = 0; i < children.length; ++i) {
|
165
|
-
const child = children[i];
|
166
|
-
|
167
|
-
if (matchComponentTypes(child, [Option])) {
|
168
|
-
if (child.props[field] === value) {
|
169
|
-
match = child;
|
170
|
-
}
|
171
|
-
} else if (matchComponentTypes(child, [Group])) {
|
172
|
-
const groupChildren = Children.toArray(child.props.children);
|
173
|
-
|
174
|
-
for (let j = 0; j < groupChildren.length; ++j) {
|
175
|
-
const groupChild = groupChildren[j];
|
176
|
-
|
177
|
-
if (groupChild.props[field] === value) {
|
178
|
-
match = groupChild;
|
179
|
-
break;
|
180
|
-
}
|
181
|
-
}
|
182
|
-
}
|
183
|
-
|
184
|
-
if (match) break;
|
185
|
-
}
|
186
|
-
|
187
|
-
return match;
|
188
|
-
};
|
189
|
-
handleRef = node => {
|
190
|
-
this.ref = node;
|
191
|
-
};
|
192
|
-
handleBlur = event => {
|
193
|
-
this.setState({
|
194
|
-
highlightedOptionId: void 0
|
195
|
-
});
|
196
|
-
|
197
|
-
if (typeof this.props.onBlur === 'function') {
|
198
|
-
this.props.onBlur(event);
|
199
|
-
}
|
200
|
-
};
|
201
|
-
handleShowOptions = event => {
|
202
|
-
this.setState({
|
203
|
-
isShowingOptions: true
|
204
|
-
});
|
205
|
-
|
206
|
-
if (typeof this.props.onShowOptions === 'function') {
|
207
|
-
this.props.onShowOptions(event);
|
208
|
-
}
|
209
|
-
};
|
210
|
-
handleHideOptions = event => {
|
211
|
-
this.setState(state => {
|
212
|
-
const option = this.getOption('id', state.selectedOptionId);
|
213
|
-
return {
|
214
|
-
isShowingOptions: false,
|
215
|
-
highlightedOptionId: void 0,
|
216
|
-
inputValue: option ? option.props.children : ''
|
217
|
-
};
|
218
|
-
});
|
219
|
-
|
220
|
-
if (typeof this.props.onHideOptions === 'function') {
|
221
|
-
this.props.onHideOptions(event);
|
222
|
-
}
|
223
|
-
};
|
224
|
-
handleHighlightOption = (event, _ref) => {
|
225
|
-
let id = _ref.id;
|
226
|
-
if (id === this._emptyOptionId) return;
|
227
|
-
const option = this.getOption('id', id);
|
228
|
-
const label = option === null || option === void 0 ? void 0 : option.props.children;
|
229
|
-
const inputValue = event.type === 'keydown' ? label : this.state.inputValue;
|
230
|
-
this.setState({
|
231
|
-
highlightedOptionId: id,
|
232
|
-
inputValue
|
233
|
-
});
|
234
|
-
};
|
235
|
-
handleSelectOption = (event, _ref2) => {
|
236
|
-
let id = _ref2.id;
|
237
|
-
|
238
|
-
if (id === this._emptyOptionId) {
|
239
|
-
// selected option is the empty option
|
240
|
-
this.setState({
|
241
|
-
isShowingOptions: false
|
242
|
-
});
|
243
|
-
return;
|
244
|
-
}
|
245
|
-
|
246
|
-
const option = this.getOption('id', id);
|
247
|
-
const value = option && option.props.value;
|
248
|
-
|
249
|
-
if (this.isControlled) {
|
250
|
-
this.setState({
|
251
|
-
isShowingOptions: false
|
252
|
-
});
|
253
|
-
} else {
|
254
|
-
this.setState(state => ({
|
255
|
-
isShowingOptions: false,
|
256
|
-
selectedOptionId: id,
|
257
|
-
inputValue: option ? option.props.children : state.inputValue
|
258
|
-
}));
|
259
|
-
} // fire onChange if selected option changed
|
260
|
-
|
261
|
-
|
262
|
-
if (option && typeof this.props.onChange === 'function') {
|
263
|
-
this.props.onChange(event, {
|
264
|
-
value,
|
265
|
-
id
|
266
|
-
});
|
267
|
-
} // hide options list whenever selection is made
|
268
|
-
|
269
|
-
|
270
|
-
if (typeof this.props.onHideOptions === 'function') {
|
271
|
-
this.props.onHideOptions(event);
|
272
|
-
}
|
273
|
-
};
|
274
|
-
|
275
267
|
renderChildren() {
|
276
268
|
let children = Children.toArray(this.props.children);
|
277
269
|
children = Children.map(children, child => {
|
@@ -415,6 +407,14 @@ let SimpleSelect = (_dec = withDeterministicId(), _dec2 = testable(), _dec(_clas
|
|
415
407
|
}, passthroughProps(rest)), this.renderChildren());
|
416
408
|
}
|
417
409
|
|
418
|
-
}
|
410
|
+
}, _class2.displayName = "SimpleSelect", _class2.componentId = 'SimpleSelect', _class2.Option = Option, _class2.Group = Group, _class2.allowedProps = allowedProps, _class2.propTypes = propTypes, _class2.defaultProps = {
|
411
|
+
size: 'medium',
|
412
|
+
isRequired: false,
|
413
|
+
isInline: false,
|
414
|
+
visibleOptionsCount: 8,
|
415
|
+
placement: 'bottom stretch',
|
416
|
+
constrain: 'window',
|
417
|
+
renderEmptyOption: '---'
|
418
|
+
}, _class2)) || _class) || _class);
|
419
419
|
export { SimpleSelect };
|
420
420
|
export default SimpleSelect;
|
@@ -41,13 +41,7 @@ id: SimpleSelect.Group
|
|
41
41
|
@tsProps
|
42
42
|
**/
|
43
43
|
class Group extends _react.Component {
|
44
|
-
static displayName = "Group";
|
45
|
-
static componentId = 'SimpleSelect.Group';
|
46
|
-
static allowedProps = _props.allowedProps;
|
47
|
-
static propTypes = _props.propTypes;
|
48
|
-
static defaultProps = {};
|
49
44
|
/* istanbul ignore next */
|
50
|
-
|
51
45
|
render() {
|
52
46
|
// this component is only used for prop validation. Select.Group children
|
53
47
|
// are parsed in Select and rendered as Options components
|
@@ -57,5 +51,10 @@ class Group extends _react.Component {
|
|
57
51
|
}
|
58
52
|
|
59
53
|
exports.Group = Group;
|
54
|
+
Group.displayName = "Group";
|
55
|
+
Group.componentId = 'SimpleSelect.Group';
|
56
|
+
Group.allowedProps = _props.allowedProps;
|
57
|
+
Group.propTypes = _props.propTypes;
|
58
|
+
Group.defaultProps = {};
|
60
59
|
var _default = Group;
|
61
60
|
exports.default = _default;
|
@@ -41,15 +41,7 @@ id: SimpleSelect.Option
|
|
41
41
|
@tsProps
|
42
42
|
**/
|
43
43
|
class Option extends _react.Component {
|
44
|
-
static displayName = "Option";
|
45
|
-
static componentId = 'SimpleSelect.Option';
|
46
|
-
static allowedProps = _props.allowedProps;
|
47
|
-
static propTypes = _props.propTypes;
|
48
|
-
static defaultProps = {
|
49
|
-
isDisabled: false
|
50
|
-
};
|
51
44
|
/* istanbul ignore next */
|
52
|
-
|
53
45
|
render() {
|
54
46
|
// this component is only used for prop validation. SimpleSelect.Option children
|
55
47
|
// are parsed in Select and rendered as Options.Item components
|
@@ -59,5 +51,12 @@ class Option extends _react.Component {
|
|
59
51
|
}
|
60
52
|
|
61
53
|
exports.Option = Option;
|
54
|
+
Option.displayName = "Option";
|
55
|
+
Option.componentId = 'SimpleSelect.Option';
|
56
|
+
Option.allowedProps = _props.allowedProps;
|
57
|
+
Option.propTypes = _props.propTypes;
|
58
|
+
Option.defaultProps = {
|
59
|
+
isDisabled: false
|
60
|
+
};
|
62
61
|
var _default = Option;
|
63
62
|
exports.default = _default;
|
@@ -37,7 +37,7 @@ const _excluded = ["id", "value", "children", "renderBeforeLabel", "renderAfterL
|
|
37
37
|
_excluded2 = ["id", "renderLabel", "children"],
|
38
38
|
_excluded3 = ["renderLabel", "value", "defaultValue", "id", "size", "assistiveText", "placeholder", "interaction", "isRequired", "isInline", "width", "optionsMaxWidth", "optionsMaxHeight", "visibleOptionsCount", "messages", "placement", "constrain", "mountNode", "inputRef", "listRef", "renderEmptyOption", "renderBeforeInput", "renderAfterInput", "onFocus", "onBlur", "onShowOptions", "onHideOptions", "children"];
|
39
39
|
|
40
|
-
var _dec, _dec2, _class;
|
40
|
+
var _dec, _dec2, _class, _class2;
|
41
41
|
|
42
42
|
/**
|
43
43
|
---
|
@@ -46,33 +46,141 @@ tags: form, field, dropdown
|
|
46
46
|
---
|
47
47
|
@tsProps
|
48
48
|
**/
|
49
|
-
let SimpleSelect = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _testable.testable)(), _dec(_class = _dec2(_class = class SimpleSelect extends _react.Component {
|
50
|
-
static displayName = "SimpleSelect";
|
51
|
-
static componentId = 'SimpleSelect';
|
52
|
-
static Option = _Option.Option;
|
53
|
-
static Group = _Group.Group;
|
54
|
-
static allowedProps = _props.allowedProps;
|
55
|
-
static propTypes = _props.propTypes;
|
56
|
-
static defaultProps = {
|
57
|
-
size: 'medium',
|
58
|
-
isRequired: false,
|
59
|
-
isInline: false,
|
60
|
-
visibleOptionsCount: 8,
|
61
|
-
placement: 'bottom stretch',
|
62
|
-
constrain: 'window',
|
63
|
-
renderEmptyOption: '---'
|
64
|
-
};
|
65
|
-
ref = null;
|
66
|
-
_emptyOptionId;
|
67
|
-
|
49
|
+
let SimpleSelect = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _testable.testable)(), _dec(_class = _dec2(_class = (_class2 = class SimpleSelect extends _react.Component {
|
68
50
|
constructor(props) {
|
69
51
|
super(props);
|
70
|
-
|
52
|
+
this.ref = null;
|
53
|
+
this._emptyOptionId = void 0;
|
54
|
+
|
55
|
+
this.getOption = (field, value) => {
|
56
|
+
const children = _react.Children.toArray(this.props.children);
|
57
|
+
|
58
|
+
let match;
|
59
|
+
|
60
|
+
for (let i = 0; i < children.length; ++i) {
|
61
|
+
const child = children[i];
|
62
|
+
|
63
|
+
if ((0, _matchComponentTypes.matchComponentTypes)(child, [_Option.Option])) {
|
64
|
+
if (child.props[field] === value) {
|
65
|
+
match = child;
|
66
|
+
}
|
67
|
+
} else if ((0, _matchComponentTypes.matchComponentTypes)(child, [_Group.Group])) {
|
68
|
+
const groupChildren = _react.Children.toArray(child.props.children);
|
69
|
+
|
70
|
+
for (let j = 0; j < groupChildren.length; ++j) {
|
71
|
+
const groupChild = groupChildren[j];
|
72
|
+
|
73
|
+
if (groupChild.props[field] === value) {
|
74
|
+
match = groupChild;
|
75
|
+
break;
|
76
|
+
}
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
if (match) break;
|
81
|
+
}
|
82
|
+
|
83
|
+
return match;
|
84
|
+
};
|
85
|
+
|
86
|
+
this.handleRef = node => {
|
87
|
+
this.ref = node;
|
88
|
+
};
|
89
|
+
|
90
|
+
this.handleBlur = event => {
|
91
|
+
this.setState({
|
92
|
+
highlightedOptionId: void 0
|
93
|
+
});
|
94
|
+
|
95
|
+
if (typeof this.props.onBlur === 'function') {
|
96
|
+
this.props.onBlur(event);
|
97
|
+
}
|
98
|
+
};
|
99
|
+
|
100
|
+
this.handleShowOptions = event => {
|
101
|
+
this.setState({
|
102
|
+
isShowingOptions: true
|
103
|
+
});
|
104
|
+
|
105
|
+
if (typeof this.props.onShowOptions === 'function') {
|
106
|
+
this.props.onShowOptions(event);
|
107
|
+
}
|
108
|
+
};
|
109
|
+
|
110
|
+
this.handleHideOptions = event => {
|
111
|
+
this.setState(state => {
|
112
|
+
const option = this.getOption('id', state.selectedOptionId);
|
113
|
+
return {
|
114
|
+
isShowingOptions: false,
|
115
|
+
highlightedOptionId: void 0,
|
116
|
+
inputValue: option ? option.props.children : ''
|
117
|
+
};
|
118
|
+
});
|
119
|
+
|
120
|
+
if (typeof this.props.onHideOptions === 'function') {
|
121
|
+
this.props.onHideOptions(event);
|
122
|
+
}
|
123
|
+
};
|
124
|
+
|
125
|
+
this.handleHighlightOption = (event, _ref) => {
|
126
|
+
let id = _ref.id;
|
127
|
+
if (id === this._emptyOptionId) return;
|
128
|
+
const option = this.getOption('id', id);
|
129
|
+
const label = option === null || option === void 0 ? void 0 : option.props.children;
|
130
|
+
const inputValue = event.type === 'keydown' ? label : this.state.inputValue;
|
131
|
+
this.setState({
|
132
|
+
highlightedOptionId: id,
|
133
|
+
inputValue
|
134
|
+
});
|
135
|
+
};
|
136
|
+
|
137
|
+
this.handleSelectOption = (event, _ref2) => {
|
138
|
+
let id = _ref2.id;
|
139
|
+
|
140
|
+
if (id === this._emptyOptionId) {
|
141
|
+
// selected option is the empty option
|
142
|
+
this.setState({
|
143
|
+
isShowingOptions: false
|
144
|
+
});
|
145
|
+
return;
|
146
|
+
}
|
147
|
+
|
148
|
+
const option = this.getOption('id', id);
|
149
|
+
const value = option && option.props.value;
|
150
|
+
|
151
|
+
if (this.isControlled) {
|
152
|
+
this.setState({
|
153
|
+
isShowingOptions: false
|
154
|
+
});
|
155
|
+
} else {
|
156
|
+
this.setState(state => ({
|
157
|
+
isShowingOptions: false,
|
158
|
+
selectedOptionId: id,
|
159
|
+
inputValue: option ? option.props.children : state.inputValue
|
160
|
+
}));
|
161
|
+
} // fire onChange if selected option changed
|
162
|
+
|
163
|
+
|
164
|
+
if (option && typeof this.props.onChange === 'function') {
|
165
|
+
this.props.onChange(event, {
|
166
|
+
value,
|
167
|
+
id
|
168
|
+
});
|
169
|
+
} // hide options list whenever selection is made
|
170
|
+
|
171
|
+
|
172
|
+
if (typeof this.props.onHideOptions === 'function') {
|
173
|
+
this.props.onHideOptions(event);
|
174
|
+
}
|
175
|
+
};
|
176
|
+
|
177
|
+
const _option = this.getInitialOption(props);
|
178
|
+
|
71
179
|
this.state = {
|
72
|
-
inputValue:
|
180
|
+
inputValue: _option ? _option.props.children : '',
|
73
181
|
isShowingOptions: false,
|
74
182
|
highlightedOptionId: void 0,
|
75
|
-
selectedOptionId:
|
183
|
+
selectedOptionId: _option ? _option.props.id : void 0
|
76
184
|
};
|
77
185
|
this._emptyOptionId = props.deterministicId('Select-EmptyOption');
|
78
186
|
}
|
@@ -161,122 +269,6 @@ let SimpleSelect = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec
|
|
161
269
|
return match;
|
162
270
|
}
|
163
271
|
|
164
|
-
getOption = (field, value) => {
|
165
|
-
const children = _react.Children.toArray(this.props.children);
|
166
|
-
|
167
|
-
let match;
|
168
|
-
|
169
|
-
for (let i = 0; i < children.length; ++i) {
|
170
|
-
const child = children[i];
|
171
|
-
|
172
|
-
if ((0, _matchComponentTypes.matchComponentTypes)(child, [_Option.Option])) {
|
173
|
-
if (child.props[field] === value) {
|
174
|
-
match = child;
|
175
|
-
}
|
176
|
-
} else if ((0, _matchComponentTypes.matchComponentTypes)(child, [_Group.Group])) {
|
177
|
-
const groupChildren = _react.Children.toArray(child.props.children);
|
178
|
-
|
179
|
-
for (let j = 0; j < groupChildren.length; ++j) {
|
180
|
-
const groupChild = groupChildren[j];
|
181
|
-
|
182
|
-
if (groupChild.props[field] === value) {
|
183
|
-
match = groupChild;
|
184
|
-
break;
|
185
|
-
}
|
186
|
-
}
|
187
|
-
}
|
188
|
-
|
189
|
-
if (match) break;
|
190
|
-
}
|
191
|
-
|
192
|
-
return match;
|
193
|
-
};
|
194
|
-
handleRef = node => {
|
195
|
-
this.ref = node;
|
196
|
-
};
|
197
|
-
handleBlur = event => {
|
198
|
-
this.setState({
|
199
|
-
highlightedOptionId: void 0
|
200
|
-
});
|
201
|
-
|
202
|
-
if (typeof this.props.onBlur === 'function') {
|
203
|
-
this.props.onBlur(event);
|
204
|
-
}
|
205
|
-
};
|
206
|
-
handleShowOptions = event => {
|
207
|
-
this.setState({
|
208
|
-
isShowingOptions: true
|
209
|
-
});
|
210
|
-
|
211
|
-
if (typeof this.props.onShowOptions === 'function') {
|
212
|
-
this.props.onShowOptions(event);
|
213
|
-
}
|
214
|
-
};
|
215
|
-
handleHideOptions = event => {
|
216
|
-
this.setState(state => {
|
217
|
-
const option = this.getOption('id', state.selectedOptionId);
|
218
|
-
return {
|
219
|
-
isShowingOptions: false,
|
220
|
-
highlightedOptionId: void 0,
|
221
|
-
inputValue: option ? option.props.children : ''
|
222
|
-
};
|
223
|
-
});
|
224
|
-
|
225
|
-
if (typeof this.props.onHideOptions === 'function') {
|
226
|
-
this.props.onHideOptions(event);
|
227
|
-
}
|
228
|
-
};
|
229
|
-
handleHighlightOption = (event, _ref) => {
|
230
|
-
let id = _ref.id;
|
231
|
-
if (id === this._emptyOptionId) return;
|
232
|
-
const option = this.getOption('id', id);
|
233
|
-
const label = option === null || option === void 0 ? void 0 : option.props.children;
|
234
|
-
const inputValue = event.type === 'keydown' ? label : this.state.inputValue;
|
235
|
-
this.setState({
|
236
|
-
highlightedOptionId: id,
|
237
|
-
inputValue
|
238
|
-
});
|
239
|
-
};
|
240
|
-
handleSelectOption = (event, _ref2) => {
|
241
|
-
let id = _ref2.id;
|
242
|
-
|
243
|
-
if (id === this._emptyOptionId) {
|
244
|
-
// selected option is the empty option
|
245
|
-
this.setState({
|
246
|
-
isShowingOptions: false
|
247
|
-
});
|
248
|
-
return;
|
249
|
-
}
|
250
|
-
|
251
|
-
const option = this.getOption('id', id);
|
252
|
-
const value = option && option.props.value;
|
253
|
-
|
254
|
-
if (this.isControlled) {
|
255
|
-
this.setState({
|
256
|
-
isShowingOptions: false
|
257
|
-
});
|
258
|
-
} else {
|
259
|
-
this.setState(state => ({
|
260
|
-
isShowingOptions: false,
|
261
|
-
selectedOptionId: id,
|
262
|
-
inputValue: option ? option.props.children : state.inputValue
|
263
|
-
}));
|
264
|
-
} // fire onChange if selected option changed
|
265
|
-
|
266
|
-
|
267
|
-
if (option && typeof this.props.onChange === 'function') {
|
268
|
-
this.props.onChange(event, {
|
269
|
-
value,
|
270
|
-
id
|
271
|
-
});
|
272
|
-
} // hide options list whenever selection is made
|
273
|
-
|
274
|
-
|
275
|
-
if (typeof this.props.onHideOptions === 'function') {
|
276
|
-
this.props.onHideOptions(event);
|
277
|
-
}
|
278
|
-
};
|
279
|
-
|
280
272
|
renderChildren() {
|
281
273
|
let children = _react.Children.toArray(this.props.children);
|
282
274
|
|
@@ -418,7 +410,15 @@ let SimpleSelect = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec
|
|
418
410
|
}, (0, _passthroughProps.passthroughProps)(rest)), this.renderChildren());
|
419
411
|
}
|
420
412
|
|
421
|
-
}
|
413
|
+
}, _class2.displayName = "SimpleSelect", _class2.componentId = 'SimpleSelect', _class2.Option = _Option.Option, _class2.Group = _Group.Group, _class2.allowedProps = _props.allowedProps, _class2.propTypes = _props.propTypes, _class2.defaultProps = {
|
414
|
+
size: 'medium',
|
415
|
+
isRequired: false,
|
416
|
+
isInline: false,
|
417
|
+
visibleOptionsCount: 8,
|
418
|
+
placement: 'bottom stretch',
|
419
|
+
constrain: 'window',
|
420
|
+
renderEmptyOption: '---'
|
421
|
+
}, _class2)) || _class) || _class);
|
422
422
|
exports.SimpleSelect = SimpleSelect;
|
423
423
|
var _default = SimpleSelect;
|
424
424
|
exports.default = _default;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@instructure/ui-simple-select",
|
3
|
-
"version": "8.25.1-snapshot-
|
3
|
+
"version": "8.25.1-snapshot-13",
|
4
4
|
"description": "A component for standard select element behavior.",
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
6
6
|
"module": "./es/index.js",
|
@@ -24,22 +24,22 @@
|
|
24
24
|
"license": "MIT",
|
25
25
|
"dependencies": {
|
26
26
|
"@babel/runtime": "^7.13.10",
|
27
|
-
"@instructure/console": "8.25.1-snapshot-
|
28
|
-
"@instructure/shared-types": "8.25.1-snapshot-
|
29
|
-
"@instructure/ui-form-field": "8.25.1-snapshot-
|
30
|
-
"@instructure/ui-position": "8.25.1-snapshot-
|
31
|
-
"@instructure/ui-prop-types": "8.25.1-snapshot-
|
32
|
-
"@instructure/ui-react-utils": "8.25.1-snapshot-
|
33
|
-
"@instructure/ui-select": "8.25.1-snapshot-
|
34
|
-
"@instructure/ui-testable": "8.25.1-snapshot-
|
27
|
+
"@instructure/console": "8.25.1-snapshot-13",
|
28
|
+
"@instructure/shared-types": "8.25.1-snapshot-13",
|
29
|
+
"@instructure/ui-form-field": "8.25.1-snapshot-13",
|
30
|
+
"@instructure/ui-position": "8.25.1-snapshot-13",
|
31
|
+
"@instructure/ui-prop-types": "8.25.1-snapshot-13",
|
32
|
+
"@instructure/ui-react-utils": "8.25.1-snapshot-13",
|
33
|
+
"@instructure/ui-select": "8.25.1-snapshot-13",
|
34
|
+
"@instructure/ui-testable": "8.25.1-snapshot-13",
|
35
35
|
"prop-types": "^15"
|
36
36
|
},
|
37
37
|
"devDependencies": {
|
38
|
-
"@instructure/ui-babel-preset": "8.25.1-snapshot-
|
39
|
-
"@instructure/ui-color-utils": "8.25.1-snapshot-
|
40
|
-
"@instructure/ui-icons": "8.25.1-snapshot-
|
41
|
-
"@instructure/ui-test-locator": "8.25.1-snapshot-
|
42
|
-
"@instructure/ui-test-utils": "8.25.1-snapshot-
|
38
|
+
"@instructure/ui-babel-preset": "8.25.1-snapshot-13",
|
39
|
+
"@instructure/ui-color-utils": "8.25.1-snapshot-13",
|
40
|
+
"@instructure/ui-icons": "8.25.1-snapshot-13",
|
41
|
+
"@instructure/ui-test-locator": "8.25.1-snapshot-13",
|
42
|
+
"@instructure/ui-test-utils": "8.25.1-snapshot-13"
|
43
43
|
},
|
44
44
|
"peerDependencies": {
|
45
45
|
"react": ">=16.8 <=17"
|