File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
src/components/tile-manager Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ import type IgcTileManagerComponent from './tile-manager.js';
33import type IgcTileComponent from './tile.js' ;
44
55class TilesState {
6+ private _nextEmptyPosition = 0 ;
7+
68 public manager : IgcTileManagerComponent ;
79
810 private get _tiles ( ) : IgcTileComponent [ ] {
@@ -62,7 +64,11 @@ class TilesState {
6264 }
6365 }
6466 } else {
65- tile . position = tiles . length ;
67+ const positionedTiles = this . _tiles . filter ( ( tile ) => tile . position > - 1 ) ;
68+ tile . position =
69+ positionedTiles . length > 1
70+ ? Math . max ( ...positionedTiles . map ( ( tile ) => tile . position ) ) + 1
71+ : this . _nextEmptyPosition ++ ;
6672 }
6773 }
6874
Original file line number Diff line number Diff line change @@ -685,6 +685,21 @@ describe('Tile Manager component', () => {
685685 } ) ;
686686 } ) ;
687687
688+ it ( 'should correctly position tiles added dynamically after initialization' , async ( ) => {
689+ tileManager . replaceChildren ( ) ;
690+ const tiles = Array . from ( range ( 5 ) ) . map ( ( ) =>
691+ document . createElement ( IgcTileComponent . tagName )
692+ ) ;
693+
694+ tiles . forEach ( ( tile ) => tileManager . appendChild ( tile ) ) ;
695+ await elementUpdated ( tileManager ) ;
696+
697+ tileManager . tiles . forEach ( ( tile , index ) => {
698+ expect ( tile . position ) . to . equal ( index ) ;
699+ expect ( tile . style . order ) . to . equal ( index . toString ( ) ) ;
700+ } ) ;
701+ } ) ;
702+
688703 it ( 'should set proper CSS order based on position' , async ( ) => {
689704 const firstTile = first ( getTiles ( ) ) ;
690705 firstTile . position = 6 ;
You can’t perform that action at this time.
0 commit comments