File tree Expand file tree Collapse file tree
packages/field-highlighter Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -231,16 +231,25 @@ export class UserTags extends PolymerElement {
231231
232232 if ( this . opened && this . hasFocus ) {
233233 this . updateTags ( users , changedTags ) ;
234- } else if ( addedUsers . length && document . visibilityState !== 'hidden' ) {
234+ } else if ( addedUsers . length > 0 && document . visibilityState !== 'hidden' ) {
235235 // Avoid adding to queue if window is not visible.
236- const tags = changedTags . added ;
236+
237+ const addedTags = changedTags . added ;
238+ const removedTags = changedTags . removed ;
239+
240+ // Only sync the removed user tags.
241+ // The added tags are handled by the `flashTags` method.
242+ this . updateTagsSync ( users , {
243+ added : [ ] ,
244+ removed : removedTags ,
245+ } ) ;
246+
237247 if ( this . flashing ) {
238248 // Schedule next flash later
239- this . push ( '_flashQueue' , tags ) ;
249+ this . push ( '_flashQueue' , addedTags ) ;
240250 } else {
241- this . flashTags ( tags ) ;
251+ this . flashTags ( addedTags ) ;
242252 }
243- this . set ( 'users' , users ) ;
244253 } else {
245254 this . updateTagsSync ( users , changedTags ) ;
246255 }
Original file line number Diff line number Diff line change @@ -269,6 +269,27 @@ describe('field highlighter', () => {
269269 } ) ;
270270 } ) ;
271271
272+ describe ( 'user tags' , ( ) => {
273+ let tags ;
274+
275+ it ( 'should create user tags for each added user' , async ( ) => {
276+ addUser ( user1 ) ;
277+ addUser ( user2 ) ;
278+ await wrapper . flashPromise ;
279+ tags = getTags ( ) ;
280+ expect ( tags . length ) . to . equal ( 2 ) ;
281+ } ) ;
282+
283+ it ( 'should replace user tags when replacing users' , async ( ) => {
284+ setUsers ( [ user1 , user2 ] ) ;
285+ await wrapper . flashPromise ;
286+ setUsers ( [ user3 ] ) ;
287+ await wrapper . flashPromise ;
288+ tags = getTags ( ) ;
289+ expect ( tags . length ) . to . equal ( 1 ) ;
290+ } ) ;
291+ } ) ;
292+
272293 describe ( 'user tags opened' , ( ) => {
273294 let tags ;
274295
@@ -297,6 +318,13 @@ describe('field highlighter', () => {
297318 expect ( tags . length ) . to . equal ( 1 ) ;
298319 } ) ;
299320
321+ it ( 'should replace user tags when replacing users' , async ( ) => {
322+ setUsers ( [ user1 , user2 ] ) ;
323+ setUsers ( [ user3 ] ) ;
324+ tags = getTags ( ) ;
325+ expect ( tags . length ) . to . equal ( 1 ) ;
326+ } ) ;
327+
300328 it ( 'should set tag background color based on user index' , ( ) => {
301329 setUsers ( [ user1 , user2 ] ) ;
302330 tags = getTags ( ) ;
You can’t perform that action at this time.
0 commit comments