@@ -322,50 +322,17 @@ const sendUpdateCartRequest = async (updateUrl: string, quantity: number) => {
322322 return response ;
323323} ;
324324
325- export const populateMinQuantityInput = ( selector = quantityInputMap . default ) => {
326- const qtyInputNodeList = document . querySelectorAll < HTMLElement > ( selector ) ;
327-
328- const products = window . prestashop ?. cart ?. products ;
329-
330- if ( ! Array . isArray ( products ) || products . length === 0 ) {
331- return ;
332- }
333-
334- qtyInputNodeList . forEach ( ( qtyInputWrapper : HTMLElement ) => {
335- const form = qtyInputWrapper . closest ( 'form' ) ;
336- const idProductInput = form ?. querySelector < HTMLInputElement > ( quantityInputMap . idProductInput ) ;
337- const qtyInput = qtyInputWrapper . querySelector < HTMLInputElement > ( 'input' ) ;
338-
339- if ( ! idProductInput || ! qtyInput ) return ;
340-
341- const idProduct = parseInt ( idProductInput . value , 10 ) ;
342- const minAttr = qtyInput . getAttribute ( 'min' ) ;
343-
344- if ( ! minAttr ) return ;
345-
346- const min = parseInt ( minAttr , 10 ) ;
347- const productInCart = products . find ( ( p : { id : number } ) => p . id === idProduct ) ;
348-
349- const minimalQuantity = productInCart && productInCart . quantity_wanted >= min ? 1 : min ;
350-
351- qtyInput . setAttribute ( 'min' , minimalQuantity . toString ( ) ) ;
352- qtyInput . setAttribute ( 'value' , minimalQuantity . toString ( ) ) ;
353- } ) ;
354- } ;
355-
356325document . addEventListener ( 'DOMContentLoaded' , ( ) => {
357326 const { prestashop, Theme : { events} } = window ;
358327
359- populateMinQuantityInput ( ) ;
360-
361328 // Delegated keydown: store focus only on Enter key press
362329 document . addEventListener ( 'keydown' , ( e : KeyboardEvent ) => {
363330 const target = e . target as HTMLElement | null ;
364331
365332 if ( ! target ) return ;
366333
367334 // If Enter key pressed and element is inside productQuantity wrapper, store focus
368- if ( e . key === ENTER_KEY && target . closest ( cartSelectorMap . productQuantity ) ) {
335+ if ( ( e . key === ENTER_KEY || e . key === ' ' || e . code === 'Space' ) && target . closest ( cartSelectorMap . productQuantity ) ) {
369336 // Set state.lastUpdateAction to track the last update action
370337 state . set ( 'lastUpdateAction' , availableLastUpdateAction . UPDATE_PRODUCT_QUANTITY ) ;
371338 a11y . storeFocus ( ) ;
@@ -381,7 +348,7 @@ document.addEventListener('DOMContentLoaded', () => {
381348 // nearest button inside the product quantity wrapper
382349 const btn = target . closest ( `${ cartSelectorMap . productQuantity } button` ) as HTMLElement | null ;
383350
384- if ( btn && ( e . key === ENTER_KEY || e . key === ' ' ) ) {
351+ if ( btn && ( e . key === ENTER_KEY || e . key === ' ' || e . code === 'Space' ) ) {
385352 // Set state.lastUpdateAction to track the last update action
386353 state . set ( 'lastUpdateAction' , availableLastUpdateAction . UPDATE_PRODUCT_QUANTITY ) ;
387354 a11y . storeFocus ( ) ;
@@ -390,16 +357,10 @@ document.addEventListener('DOMContentLoaded', () => {
390357
391358 prestashop . on ( events . updatedCart , ( ) => {
392359 useQuantityInput ( cartSelectorMap . productQuantity ) ;
393- populateMinQuantityInput ( ) ;
394- } ) ;
395-
396- prestashop . on ( events . updateProduct , ( ) => {
397- populateMinQuantityInput ( ) ;
398360 } ) ;
399361
400362 prestashop . on ( events . quickviewOpened , ( ) => {
401363 useQuantityInput ( quantityInputMap . modal ) ;
402- populateMinQuantityInput ( quantityInputMap . modal ) ;
403364 } ) ;
404365} ) ;
405366
0 commit comments