Skip to content

Commit 8161fec

Browse files
committed
Update src/browser/component/TagSelect.js
1 parent 97134cb commit 8161fec

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/browser/component/TagSelect.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// LICENSE : MIT
22
"use strict";
33
import React, { useRef, useEffect, useImperativeHandle } from "react";
4-
import Select from "react-select";
4+
import CreatableSelect from "react-select/creatable";
55

66
function TagSelect({ tags, selectedTags, selectTags, ref }) {
77
const selectRef = useRef(null);
@@ -35,6 +35,14 @@ function TagSelect({ tags, selectedTags, selectTags, ref }) {
3535
selectTags(tags);
3636
};
3737

38+
const handleCreate = (inputValue) => {
39+
const newTag = inputValue.trim();
40+
if (newTag) {
41+
const updatedTags = [...selectedTags, newTag];
42+
selectTags(updatedTags);
43+
}
44+
};
45+
3846
// react-selectのスタイルをTitleInputやURLInputと統一
3947
const customStyles = {
4048
control: (provided) => ({
@@ -95,19 +103,21 @@ function TagSelect({ tags, selectedTags, selectTags, ref }) {
95103
return (
96104
<div className="EditorToolbar">
97105
<h2 className="l-header">Tags</h2>
98-
<Select
106+
<CreatableSelect
99107
ref={selectRef}
100108
name="form-field-name"
101109
value={selectedOptions}
102110
options={options}
103111
isMulti
104112
isClearable
105-
placeholder="Select Tag(s)"
113+
placeholder="Select or create tag(s)"
106114
onChange={handleChange}
115+
onCreateOption={handleCreate}
107116
styles={customStyles}
108117
menuPosition="fixed"
109118
menuPortalTarget={document.body}
110119
menuShouldBlockScroll={false}
120+
formatCreateLabel={(inputValue) => `Create "${inputValue}"`}
111121
/>
112122
</div>
113123
);

0 commit comments

Comments
 (0)