fix(checkout): disable cart access
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
<button
|
||||
type="button"
|
||||
[disabled]="disabled()"
|
||||
[class.cart-icon--disabled]="disabled()"
|
||||
[attr.aria-label]="ariaLabel()"
|
||||
[attr.aria-disabled]="disabled()"
|
||||
class="cart-icon"
|
||||
>
|
||||
<div class="cart-icon__container">
|
||||
|
||||
@@ -14,7 +14,9 @@
|
||||
color: #666666;
|
||||
cursor: pointer;
|
||||
outline: none;
|
||||
transition: color 0.15s ease-in-out, transform 0.1s ease-in-out;
|
||||
transition:
|
||||
color 0.15s ease-in-out,
|
||||
transform 0.1s ease-in-out;
|
||||
border-radius: 4px;
|
||||
|
||||
// Active state subtle scale down
|
||||
@@ -29,10 +31,12 @@
|
||||
}
|
||||
|
||||
// Disabled state
|
||||
&:disabled {
|
||||
color: #A0A0A0;
|
||||
&:disabled,
|
||||
&.cart-icon--disabled {
|
||||
color: #b8b8b8;
|
||||
cursor: not-allowed;
|
||||
pointer-events: none;
|
||||
opacity: 0.45;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +63,11 @@
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.cart-icon:disabled .cart-icon__glyph,
|
||||
.cart-icon--disabled .cart-icon__glyph {
|
||||
color: #b8b8b8;
|
||||
}
|
||||
|
||||
.cart-icon__badge {
|
||||
position: absolute;
|
||||
top: -8px;
|
||||
|
||||
@@ -6,7 +6,7 @@ import { CartIconComponent } from './cart-icon.component';
|
||||
describe('CartIconComponent', () => {
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [CartIconComponent]
|
||||
imports: [CartIconComponent],
|
||||
}).compileComponents();
|
||||
});
|
||||
|
||||
@@ -20,7 +20,7 @@ describe('CartIconComponent', () => {
|
||||
|
||||
return {
|
||||
fixture,
|
||||
element: fixture.nativeElement as HTMLElement
|
||||
element: fixture.nativeElement as HTMLElement,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -47,9 +47,11 @@ describe('CartIconComponent', () => {
|
||||
});
|
||||
|
||||
it('disables the button when disabled is true', () => {
|
||||
const { element } = setup(undefined, true);
|
||||
const { element } = setup(3, true);
|
||||
const button = element.querySelector('button');
|
||||
expect(button?.disabled).toBe(true);
|
||||
expect(button?.classList).toContain('cart-icon--disabled');
|
||||
expect(element.querySelector('[data-testid="cart-badge"]')).toBeNull();
|
||||
});
|
||||
|
||||
it('enables the button when disabled is false', () => {
|
||||
|
||||
@@ -5,7 +5,7 @@ import { ChangeDetectionStrategy, Component, computed, input } from '@angular/co
|
||||
imports: [],
|
||||
templateUrl: './cart-icon.component.html',
|
||||
styleUrl: './cart-icon.component.scss',
|
||||
changeDetection: ChangeDetectionStrategy.OnPush
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class CartIconComponent {
|
||||
readonly quantity = input<number | null | undefined>(undefined);
|
||||
@@ -13,6 +13,10 @@ export class CartIconComponent {
|
||||
readonly ariaLabel = input<string>('Carrito de compras');
|
||||
|
||||
protected readonly hasQuantity = computed(() => {
|
||||
if (this.disabled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const q = this.quantity();
|
||||
return q !== null && q !== undefined && q > 0;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user