@@ -37,7 +37,6 @@ export interface TagSelectorProps {
3737 createTags ?: boolean ;
3838 allowDuplicateKeys ?: boolean ;
3939 onlySelectKeys ?: boolean ;
40- removeWhenClicked ?: boolean ;
4140}
4241
4342export const TagSelector : React . FC < TagSelectorProps > = ( {
@@ -48,7 +47,6 @@ export const TagSelector: React.FC<TagSelectorProps> = ({
4847 createTags = true ,
4948 allowDuplicateKeys = false ,
5049 onlySelectKeys = false ,
51- removeWhenClicked = false ,
5250} ) => {
5351 const classes = useStyles ( ) ;
5452 const [ tooltipErrorActive , tooltipError , showTooltipError ] = useError ( 4000 ) ;
@@ -127,14 +125,21 @@ export const TagSelector: React.FC<TagSelectorProps> = ({
127125 return ;
128126 } ;
129127
130- const onTagClicked = ( entry : TagSelectorEntry ) => {
131- if ( ! removeWhenClicked ) {
128+ const onTagClicked = ( entry : TagSelectorEntry , edit : boolean ) => {
129+ // Prevent overwriting text that's already being edited
130+ if ( currentValue && edit ) {
131+ showTooltipError ( 'Input is not empty. Use ctrl+click to delete tag without editing.' ) ;
132132 return ;
133133 }
134- const tagIndex = selectedEntries . indexOf ( entry ) ;
135- selectedEntries . splice ( tagIndex , 1 ) ;
136134
137- setSelectedEntries ( selectedEntries ) ;
135+ setSelectedEntries ( selectedEntries . filter ( ( selected ) => selected !== entry ) ) ;
136+
137+ if ( edit ) {
138+ setCurrentValueInternal ( itemLabel ( entry , onlySelectKeys ) ) ;
139+ setOpen ( true ) ;
140+ }
141+
142+ focusInput ( ) ;
138143 } ;
139144
140145 const onKeyDown = ( event : React . KeyboardEvent ) => {
@@ -177,6 +182,7 @@ export const TagSelector: React.FC<TagSelectorProps> = ({
177182 disableHoverListener
178183 disableTouchListener
179184 open = { tooltipErrorActive }
185+ PopperProps = { { style : { zIndex : 100000 } } }
180186 placement = { 'top' }
181187 title = {
182188 < Typography color = "inherit" style = { { whiteSpace : 'pre-line' } } >
@@ -217,7 +223,10 @@ export const TagSelector: React.FC<TagSelectorProps> = ({
217223 ) : null }
218224 { addDialogOpen && (
219225 < AddTagDialog
220- onAdded = { ( tag ) => trySubmit ( { tag, value : '' } ) }
226+ onAdded = { ( tag ) => {
227+ const valuePart = currentValue . split ( ':' ) [ 1 ] || '' ;
228+ trySubmit ( { tag, value : valuePart } ) ;
229+ } }
221230 open = { true }
222231 initialName = { currentValue . split ( ':' ) [ 0 ] }
223232 close = { ( ) => {
@@ -254,13 +263,17 @@ const Item: React.FC<ItemProps> = ({entry, selected, onlySelectKeys, onClick}) =
254263 ) ;
255264} ;
256265
257- const toChips = ( entries : TagSelectorEntry [ ] , onlySelectKeys : boolean , onClick : ( entry : TagSelectorEntry ) => void ) => {
266+ const toChips = (
267+ entries : TagSelectorEntry [ ] ,
268+ onlySelectKeys : boolean ,
269+ onClick : ( entry : TagSelectorEntry , edit : boolean ) => void
270+ ) => {
258271 return entries . map ( ( entry ) => (
259272 < TagChip
260273 key = { itemLabel ( entry , onlySelectKeys ) }
261274 label = { itemLabel ( entry , onlySelectKeys ) }
262275 color = { entry . tag . color }
263- onClick = { ( ) => onClick ( entry ) }
276+ onClick = { ( e ) => onClick ( entry , ! e . ctrlKey ) }
264277 />
265278 ) ) ;
266279} ;
0 commit comments