Skip to content

Commit ae19ada

Browse files
committed
tidy up tags
1 parent 3188a3c commit ae19ada

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export default function App() {
100100
const otherTags = allTags.slice(0, -1);
101101
let newTag = allTags.slice(-1)[0];
102102
// add new tag if it doesn't already exist
103-
if (newTag.inputValue) {
103+
if (newTag && newTag.inputValue) {
104104
newTag = createTag(newTag.inputValue);
105105
allTags = [...otherTags, newTag];
106106
}

src/TagsInput.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ export default function TagsInput(props) {
2626
onChange={props.onChange}
2727
inputValue={inputValue}
2828
onInputChange={(e, newInputValue) => {
29-
setInputValue(newInputValue);
29+
setInputValue(newInputValue.toLowerCase());
3030
}}
3131
multiple
3232
autoHighlight
3333
filterSelectedOptions
3434
freeSolo
35+
clearOnBlur
36+
openOnFocus
3537
filterOptions={(options, params) => {
3638
const filtered = filter(options, params);
3739
// Suggest the creation of a new value per...
@@ -44,7 +46,11 @@ export default function TagsInput(props) {
4446
}
4547
return filtered;
4648
}}
47-
options={props.options}
49+
options={props.options.sort((a, b) => {
50+
if (a.label < b.label) return -1;
51+
if (a.label > b.label) return 1;
52+
return 0;
53+
})}
4854
getOptionLabel={(option) => option.label}
4955
renderOption={(option, { inputValue }) => {
5056
const matches = match(option.label, inputValue);

0 commit comments

Comments
 (0)