@@ -17,6 +17,7 @@ const initCheckout = () => {
1717 const termsModalElement = document . querySelector < HTMLLinkElement > ( CheckoutMap . checkoutModal ) ;
1818
1919 // Only UI things, the real toggle is handled by Bootstrap Tabs
20+ // A thing we handle manually is the .active class on the toggling buttons
2021 const toggleStep = ( content : HTMLElement , step ?: HTMLElement ) => {
2122 const currentContent = document . querySelector ( CheckoutMap . steps . current ) ;
2223 currentContent ?. classList . remove ( 'step--current' , 'js-current-step' ) ;
@@ -51,18 +52,26 @@ const initCheckout = () => {
5152 } ) ;
5253 } ) ;
5354
55+ // Initial step settings
5456 steps . forEach ( ( step , index ) => {
57+ // Get step content
5558 const stepContent = document . querySelector < HTMLElement > (
5659 CheckoutMap . steps . specificStepContent ( step . dataset . step ) ,
5760 ) ;
5861
62+ // Get step selector button (toggler)
63+ const stepButton = step . querySelector < HTMLButtonElement > ( 'button' ) ;
64+
5965 if ( stepContent ) {
66+ // If step is finished, we mark it green
6067 if ( stepContent . classList . contains ( 'step--complete' ) ) {
6168 step . classList . add ( 'checkout__steps--success' ) ;
6269 }
6370
71+ // Current step will get an active property
6472 if ( stepContent . classList . contains ( 'step--current' ) ) {
6573 step . classList . add ( 'checkout__steps--current' ) ;
74+ stepButton ?. classList . add ( 'active' ) ;
6675 const responsiveStep = document . querySelector < HTMLElement > (
6776 CheckoutMap . steps . specificStep ( step . dataset . step ) ,
6877 ) ;
@@ -74,14 +83,15 @@ const initCheckout = () => {
7483 if ( setProgress ) {
7584 setProgress ( index + 1 ) ;
7685 }
86+ } else {
87+ stepButton ?. classList . remove ( 'active' ) ;
7788 }
7889
90+ // If the step can be navigated
7991 if ( stepContent . classList . contains ( 'step--reachable' ) ) {
80- const button = step . querySelector < HTMLButtonElement > ( 'button' ) ;
81-
82- button ?. classList . add ( 'btn-link' ) ;
92+ stepButton ?. classList . add ( 'btn-link' ) ;
8393
84- button ?. addEventListener ( 'click' , ( ) => {
94+ stepButton ?. addEventListener ( 'click' , ( ) => {
8595 if ( setProgress ) {
8696 setProgress ( index + 1 ) ;
8797 }
@@ -90,12 +100,10 @@ const initCheckout = () => {
90100 } ) ;
91101 }
92102
103+ // If the step is not finished yet, we disable the navigator
93104 if ( stepContent . classList . contains ( 'step--unreachable' ) ) {
94- const button = step . querySelector < HTMLButtonElement > ( 'button' ) ;
95-
96- button ?. setAttribute ( 'disabled' , 'true' ) ;
97-
98- button ?. addEventListener ( 'click' , ( ) => {
105+ stepButton ?. setAttribute ( 'disabled' , 'true' ) ;
106+ stepButton ?. addEventListener ( 'click' , ( ) => {
99107 toggleStep ( stepContent , step ) ;
100108 } ) ;
101109 }
0 commit comments