Skip to content

Commit 7ff1c3b

Browse files
authored
Исправил баг с добавлением любого символа в тэг (#333)
* Исправил баг с добавлением любого символа в тэг * Исправил проблему когда при добавлении тэга в начале фразы тире и точку пропускал * Исправил проблему когда при добавлении тэга в конце фразы тире и точку пропускал
1 parent 4c64ae0 commit 7ff1c3b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/features/questions/create-question/CreateQuestionPage.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,11 @@ const CreateQuestion = () => {
109109
const [tooManyQuestions, setTooManyQuestions] = useState(false);
110110

111111
const addTag = () => {
112-
if (!tags.includes(tagValue)) {
112+
const tagRegex = /^(?!^[.-])[a-z0-9]+(?:[-.][a-z0-9]+)*$/i;
113+
if (tagRegex.test(tagValue) && !tags.includes(tagValue)) {
113114
setTags([...tags, tagValue]);
115+
setTagValue('');
116+
setTagEditMode(false);
114117
}
115118
};
116119

@@ -127,9 +130,6 @@ const CreateQuestion = () => {
127130
const handleKeyPress = (event) => {
128131
if (event.key === 'Enter') {
129132
addTag(tagValue);
130-
131-
setTagValue('');
132-
setTagEditMode(false);
133133
}
134134
};
135135

0 commit comments

Comments
 (0)