@@ -76,6 +76,35 @@ const removePreviousHandler = function (input) {
7676 }
7777} ;
7878
79+ const getDefaultVisibleCount = function ( ) {
80+ const csContainer = document . querySelector ( '.cs_container' ) ;
81+ let defaultVisibleCount = 5 ;
82+ if ( csContainer ) {
83+ const parsed = parseInt ( csContainer . dataset . defaultVisibleTags , 10 ) ;
84+ if ( parsed > 0 ) {
85+ defaultVisibleCount = parsed ;
86+ }
87+ }
88+ return defaultVisibleCount ;
89+ } ;
90+
91+ const toggleShowMoreButtonVisibility = function (
92+ container ,
93+ isSearchActive ,
94+ totalTags ,
95+ defaultVisibleCount ,
96+ ) {
97+ const showMoreButton = container . querySelector ( '.tags__show-more' ) ;
98+ if ( showMoreButton ) {
99+ if ( isSearchActive ) {
100+ showMoreButton . style . display = 'none' ;
101+ } else {
102+ showMoreButton . style . display =
103+ totalTags > defaultVisibleCount ? 'flex' : 'none' ;
104+ }
105+ }
106+ } ;
107+
79108const setupTagSearchForInput = function ( input , options ) {
80109 const {
81110 containerSelector,
@@ -85,14 +114,7 @@ const setupTagSearchForInput = function (input, options) {
85114
86115 removePreviousHandler ( input ) ;
87116
88- const csContainer = document . querySelector ( '.cs_container' ) ;
89- let defaultVisibleCount = 5 ;
90- if ( csContainer ) {
91- const parsed = parseInt ( csContainer . dataset . defaultVisibleTags , 10 ) ;
92- if ( parsed > 0 ) {
93- defaultVisibleCount = parsed ;
94- }
95- }
117+ const defaultVisibleCount = getDefaultVisibleCount ( ) ;
96118
97119 const handler = function ( ) {
98120 const filterValue = input . value . trim ( ) . toLowerCase ( ) ;
@@ -109,19 +131,12 @@ const setupTagSearchForInput = function (input, options) {
109131 ) ;
110132 toggleNoTagsMessage ( container , hasVisible ) ;
111133
112- const showMoreButton = container . querySelector ( '.tags__show-more' ) ;
113- if ( showMoreButton ) {
114- if ( isSearchActive ) {
115- showMoreButton . style . display = 'none' ;
116- } else {
117- const totalTags = tagItems . length ;
118- if ( totalTags > defaultVisibleCount ) {
119- showMoreButton . style . display = 'flex' ;
120- } else {
121- showMoreButton . style . display = 'none' ;
122- }
123- }
124- }
134+ toggleShowMoreButtonVisibility (
135+ container ,
136+ isSearchActive ,
137+ tagItems . length ,
138+ defaultVisibleCount ,
139+ ) ;
125140 } ;
126141
127142 input . tagSearchHandler = handler ;
0 commit comments