@@ -99,9 +99,11 @@ export class ResponsiveNavHelper extends Component<ResponsiveNavHelperProps> {
9999 this . _moreItems = undefined ;
100100 this . _moreElements = [ ] ;
101101 const sizeMap = new Map < HTMLElement , number > ( ) ;
102- const { fixedItems = '.is-rsh-fixed' , showSelected} = this . options ;
102+ const { fixedItems = '.is-rsh-fixed' , moreItems = '.is-rsh-more' , showSelected} = this . options ;
103103 const $fixedItems = fixedItems ? $items . filter ( fixedItems ) : null ;
104104 const fixedItemSet = $fixedItems ?. length ? new Set ( $fixedItems ) : null ;
105+ const $moreItems = moreItems ? $items . filter ( moreItems ) : null ;
106+ const moreItemSet = $moreItems ?. length ? new Set ( $moreItems ) : null ;
105107 if ( $fixedItems ?. length ) {
106108 for ( const item of $fixedItems ) {
107109 size += this . getItemSize ( item ) ;
@@ -110,13 +112,19 @@ export class ResponsiveNavHelper extends Component<ResponsiveNavHelperProps> {
110112 for ( const item of $items ) {
111113 const $item = $ ( item ) ;
112114 const fixed = fixedItemSet ?. has ( item ) ;
115+ $item . toggleClass ( 'rsh-fixed-item' , ! ! fixed ) ;
113116 if ( fixed || $item . hasClass ( 'rsh-more' ) ) {
114117 continue ;
115118 }
116119
120+ if ( moreItemSet ?. has ( item ) ) {
121+ this . _moreElements ! . push ( item ) ;
122+ $item . css ( { display : 'none' } ) . addClass ( 'rsh-overflow-item' ) ;
123+ continue ;
124+ }
117125 const opacity = $item . css ( 'opacity' ) ;
118126 $item . css ( { display : 'flex' , opacity : 0 } ) ;
119- const itemSize = this . getItemSize ( $ item[ 0 ] as HTMLElement ) ;
127+ const itemSize = this . getItemSize ( item as HTMLElement ) ;
120128 sizeMap . set ( item , itemSize ) ;
121129
122130 if ( ! overflow ) {
@@ -134,6 +142,7 @@ export class ResponsiveNavHelper extends Component<ResponsiveNavHelperProps> {
134142 $item . css ( { opacity, display : overflow ? 'none' : 'flex' } ) . toggleClass ( 'rsh-overflow-item' , overflow ) ;
135143 }
136144
145+ const hasMoreItems = ! ! this . _moreElements ?. length ;
137146 if ( overflow ) {
138147 const overflowSize = this . _moreElements ! . reduce ( ( size , item ) => {
139148 const $item = $ ( item ) ;
@@ -152,10 +161,11 @@ export class ResponsiveNavHelper extends Component<ResponsiveNavHelperProps> {
152161 }
153162 }
154163
155- this . $element . toggleClass ( 'rsh-overflowed' , overflow ) ;
156- $more . css ( { display : overflow ? 'flex' : 'none' , opacity : 1 } ) . appendTo ( this . $element ) ;
164+ this . $element . toggleClass ( 'rsh-has-more-items' , hasMoreItems )
165+ . toggleClass ( 'rsh-overflowed' , overflow ) ;
166+ $more . css ( { display : hasMoreItems ? 'flex' : 'none' , opacity : 1 } ) . appendTo ( this . $element ) ;
157167
158- if ( overflow && showSelected ) {
168+ if ( hasMoreItems && showSelected ) {
159169 this . _renderMoreBtn ( ) ;
160170 }
161171 }
0 commit comments