File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed
features/questions/create-question Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -14,3 +14,7 @@ export const QUESTIONS_PER_PAGE = 5;
1414export const AVAILABLE_THEME_COLORS = Object . keys ( theme . colors ) ;
1515export const DEFAULT_COLOR = theme . defaultColor ;
1616export const SCROLL_TO_TOP_SHOW = 500 ;
17+
18+ export const TAG_MAX_LENGTH = 15 ;
19+
20+ export const MAX_NUMBER_OF_TAGS = 5 ;
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import { Paper } from 'components/layout/Paper';
1010import { addQuestion } from 'features/questions/questionsSlice' ;
1111import { selectProfile } from 'features/profile/profileSlice' ;
1212import { useAuth } from 'common/context/Auth/useAuth' ;
13+ import { MAX_NUMBER_OF_TAGS , TAG_MAX_LENGTH } from 'app/constants' ;
1314
1415const StyledQuestionWrapper = styled . div `
1516 & .new-tag {
@@ -130,6 +131,11 @@ const CreateQuestion = () => {
130131 setFullDescription ( instance . getMarkdown ( ) ) ;
131132 } ;
132133
134+ const handleChangeTag = ( e ) => {
135+ const limitedValue = e . target . value . substring ( 0 , TAG_MAX_LENGTH ) ;
136+ setTagValue ( limitedValue ) ;
137+ } ;
138+
133139 useEffect ( ( ) => {
134140 if ( / \? [ ^ ? ] + \? / . test ( question ) ) {
135141 setTooManyQuestions ( true ) ;
@@ -218,22 +224,21 @@ const CreateQuestion = () => {
218224 </ StyledTagBlock >
219225 ) ) }
220226
221- { ! tagEditMode && (
227+ { ! tagEditMode && tags . length < MAX_NUMBER_OF_TAGS && (
222228 < StyledTagBlock >
223229 < Tag className = "site-tag-plus" onClick = { ( ) => setTagEditMode ( true ) } >
224230 < PlusOutlined /> New Tag
225231 </ Tag >
226232 </ StyledTagBlock >
227233 ) }
228-
229234 { tagEditMode && (
230235 < StyledInputBlock >
231236 < Input
232237 ref = { callbackRef }
233238 type = "text"
234239 size = "small"
235240 value = { tagValue }
236- onChange = { ( e ) => setTagValue ( e . target . value ) }
241+ onChange = { handleChangeTag }
237242 onKeyPress = { handleKeyPress }
238243 onBlur = { ( ) => setTagEditMode ( false ) }
239244 />
You can’t perform that action at this time.
0 commit comments