Добавлен автофокус на поле количества при добавлении товара, уменьшены отступы между строками корзины

This commit is contained in:
2025-11-16 17:55:28 +03:00
parent 28d58cad34
commit adea686124
2 changed files with 17 additions and 2 deletions

View File

@@ -37,7 +37,7 @@ body {
display: flex;
align-items: center;
gap: 0.5rem;
padding: 0.5rem 0;
padding: 0.35rem 0;
border-bottom: 1px solid #e9ecef;
}

View File

@@ -146,12 +146,27 @@ function renderProducts() {
}
function addToCart(item) {
if (!cart.has(item.id)) {
const isNew = !cart.has(item.id);
if (isNew) {
cart.set(item.id, { id: item.id, name: item.name, price: Number(item.price), qty: 1, type: item.type });
} else {
cart.get(item.id).qty += 1;
}
renderCart();
// Автоматический фокус на поле количества
setTimeout(() => {
const qtyInputs = document.querySelectorAll('.qty-input');
const cartItems = Array.from(cart.keys());
const itemIndex = cartItems.indexOf(item.id);
if (itemIndex !== -1 && qtyInputs[itemIndex]) {
qtyInputs[itemIndex].focus();
qtyInputs[itemIndex].select(); // Выделяем весь текст
}
}, 50);
}
function updateQty(id, delta) {