@@ -265,6 +265,10 @@ export class FilterManager {
265265 const children = wrapper . querySelector ( '.filter-children' ) ;
266266 if ( children ) {
267267 children . classList . toggle ( 'collapsed' ) ;
268+ // After expanding, apply selected states to newly visible options
269+ if ( ! children . classList . contains ( 'collapsed' ) ) {
270+ this . applySelectedStylesToContainer ( children ) ;
271+ }
268272 }
269273 } ) ;
270274 return ;
@@ -287,6 +291,9 @@ export class FilterManager {
287291 } ) ;
288292 }
289293 } ) ;
294+
295+ // Apply selected states to already selected filters in this category
296+ this . applySelectedStylesToCategory ( categoryKey ) ;
290297 } ) ;
291298 }
292299
@@ -496,6 +503,41 @@ export class FilterManager {
496503 } ) ;
497504 }
498505
506+ /**
507+ * Apply selected styles to all options in a specific category
508+ * @param {string } categoryKey - The category key
509+ */
510+ applySelectedStylesToCategory ( categoryKey ) {
511+ this . selectedFilters . forEach ( filterId => {
512+ if ( filterId . startsWith ( `${ categoryKey } :` ) ) {
513+ const option = this . filterOptionCache . get ( filterId ) ;
514+ if ( option ) {
515+ option . classList . add ( 'selected' ) ;
516+ }
517+ }
518+ } ) ;
519+ }
520+
521+ /**
522+ * Apply selected styles to all options within a container (including nested)
523+ * @param {HTMLElement } container - The container element
524+ */
525+ applySelectedStylesToContainer ( container ) {
526+ if ( ! container ) return ;
527+
528+ const options = container . querySelectorAll ( '.filter-option[data-filter][data-value]' ) ;
529+ options . forEach ( option => {
530+ const filterKey = option . dataset . filter ;
531+ const filterValue = option . dataset . value ;
532+ if ( filterKey && filterValue ) {
533+ const filterId = `${ filterKey } :${ filterValue } ` ;
534+ if ( this . selectedFilters . has ( filterId ) ) {
535+ option . classList . add ( 'selected' ) ;
536+ }
537+ }
538+ } ) ;
539+ }
540+
499541 /**
500542 * Get human-readable filter label
501543 * @param {string } filterKey - Filter key
@@ -595,6 +637,9 @@ export class FilterManager {
595637 }
596638
597639 this . updateTriggerCount ( ) ;
640+ this . scheduleFilterUpdate ( ) ;
641+ // Reset should also trigger re-render because it changed the video-grid height
642+
598643 }
599644
600645 /**
@@ -794,10 +839,6 @@ export class FilterManager {
794839 const filterId = `${ groupKey } :${ value } ` ;
795840 if ( ! this . selectedFilters . has ( filterId ) ) {
796841 this . selectedFilters . add ( filterId ) ;
797- const option = this . filterOptionCache . get ( filterId ) ;
798- if ( option ) {
799- option . classList . add ( 'selected' ) ;
800- }
801842 this . addFilterTag ( filterId , this . getFilterLabel ( groupKey , value ) ) ;
802843 }
803844 } ) ;
@@ -806,6 +847,9 @@ export class FilterManager {
806847 this . selectAllInHierarchy ( groupKey , group . values ) ;
807848 }
808849
850+ // Apply styles to currently visible (cached and rendered) options
851+ this . applySelectedStylesToCategory ( groupKey ) ;
852+
809853 this . updateTriggerCount ( ) ;
810854 this . scheduleFilterUpdate ( ) ;
811855 }
@@ -824,10 +868,6 @@ export class FilterManager {
824868 const filterId = `${ groupKey } :${ value } ` ;
825869 if ( ! this . selectedFilters . has ( filterId ) ) {
826870 this . selectedFilters . add ( filterId ) ;
827- const option = this . filterOptionCache . get ( filterId ) ;
828- if ( option ) {
829- option . classList . add ( 'selected' ) ;
830- }
831871 this . addFilterTag ( filterId , this . getFilterLabel ( groupKey , value ) ) ;
832872 }
833873 }
@@ -881,6 +921,19 @@ export class FilterManager {
881921 // Select all leaf nodes under this path
882922 this . selectLeafNodesRecursive ( groupKey , node . children , path ) ;
883923
924+ // Apply styles to currently visible options under this path
925+ const container = document . getElementById ( 'filterGroups' ) ;
926+ if ( container ) {
927+ const pathOption = container . querySelector ( `.filter-option[data-path="${ path } "]` ) ;
928+ if ( pathOption ) {
929+ const wrapper = pathOption . closest ( '.filter-option-wrapper' ) ;
930+ const childrenContainer = wrapper ?. querySelector ( '.filter-children' ) ;
931+ if ( childrenContainer ) {
932+ this . applySelectedStylesToContainer ( childrenContainer ) ;
933+ }
934+ }
935+ }
936+
884937 this . updateTriggerCount ( ) ;
885938 this . scheduleFilterUpdate ( ) ;
886939 }
@@ -942,10 +995,6 @@ export class FilterManager {
942995 const filterId = `${ groupKey } :${ value } ` ;
943996 if ( ! this . selectedFilters . has ( filterId ) ) {
944997 this . selectedFilters . add ( filterId ) ;
945- const option = this . filterOptionCache . get ( filterId ) ;
946- if ( option ) {
947- option . classList . add ( 'selected' ) ;
948- }
949998 this . addFilterTag ( filterId , this . getFilterLabel ( groupKey , value ) ) ;
950999 }
9511000 }
0 commit comments