Добавлен автофокус на поле количества при добавлении товара, уменьшены отступы между строками корзины
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user