diff --git a/projects/coreui-angular/src/lib/alert/alert.component.spec.ts b/projects/coreui-angular/src/lib/alert/alert.component.spec.ts
index 5b8eb0b5..ca90696b 100644
--- a/projects/coreui-angular/src/lib/alert/alert.component.spec.ts
+++ b/projects/coreui-angular/src/lib/alert/alert.component.spec.ts
@@ -3,6 +3,8 @@ import { By } from '@angular/platform-browser';
import { expect } from 'vitest';
import { AlertComponent } from './alert.component';
+import { ButtonCloseDirective } from '../button';
+import { TemplateIdDirective } from '../shared';
import {
AnimationCallbackEvent,
ApplicationRef,
@@ -152,6 +154,27 @@ describe('AlertComponent with a custom class', () => {
});
});
+@Component({
+ selector: 'c-custom-close-alert',
+ template: `
+
+
+
+ `,
+ imports: [AlertComponent, ButtonCloseDirective, TemplateIdDirective]
+})
+class CustomCloseAlertComponent {}
+
+describe('AlertComponent with a custom close button', () => {
+ it('should name the custom close button', async () => {
+ const fixture = TestBed.createComponent(CustomCloseAlertComponent);
+ await fixture.whenStable();
+ const buttons = fixture.nativeElement.querySelectorAll('.btn-close');
+ expect(buttons).toHaveLength(1);
+ expect(buttons[0].getAttribute('aria-label')).toBe('Close');
+ });
+});
+
@Component({
template: `Text`,
imports: [AlertComponent]
diff --git a/projects/coreui-angular/src/lib/button/button-close.directive.spec.ts b/projects/coreui-angular/src/lib/button/button-close.directive.spec.ts
index cf93c510..dcecd5a1 100644
--- a/projects/coreui-angular/src/lib/button/button-close.directive.spec.ts
+++ b/projects/coreui-angular/src/lib/button/button-close.directive.spec.ts
@@ -1,7 +1,28 @@
-import { inputBinding, signal, WritableSignal } from '@angular/core';
-import { DirectiveFixture, TestBed } from '@angular/core/testing';
+import { Component, Directive, inputBinding, signal, WritableSignal } from '@angular/core';
+import { ComponentFixture, DirectiveFixture, TestBed } from '@angular/core/testing';
+import { By } from '@angular/platform-browser';
import { ButtonCloseDirective } from './button-close.directive';
+@Component({
+ selector: 'c-named-button-close',
+ template: `
+
+
+
+ `,
+ imports: [ButtonCloseDirective]
+})
+class NamedButtonCloseComponent {
+ readonly label = signal('Fechar');
+}
+
+@Directive({
+ selector: '[cComposedButtonClose]',
+ hostDirectives: [ButtonCloseDirective],
+ host: { 'aria-label': 'Fechar' }
+})
+class ComposedButtonCloseDirective {}
+
describe('ButtonCloseDirective', () => {
let disabled: WritableSignal;
let tabindex: WritableSignal;
@@ -48,4 +69,43 @@ describe('ButtonCloseDirective', () => {
await fixture.whenStable();
expect(fixture.nativeElement.getAttribute('tabindex')).toBe('-1');
});
+
+ it('should be named Close by default, before the first render', () => {
+ const unrenderedFixture = TestBed.createDirective(ButtonCloseDirective, { tagName: 'button' });
+ expect(unrenderedFixture.nativeElement.getAttribute('aria-label')).toBe('Close');
+ });
+
+ it('should keep the aria-label of a composing directive', async () => {
+ const composedFixture = TestBed.createDirective(ComposedButtonCloseDirective, { tagName: 'button' });
+ await composedFixture.whenStable();
+ expect(composedFixture.nativeElement.classList.contains('btn-close')).toBe(true);
+ expect(composedFixture.nativeElement.getAttribute('aria-label')).toBe('Fechar');
+ });
+});
+
+describe('ButtonCloseDirective named by the page', () => {
+ let fixture: ComponentFixture;
+
+ const names = () =>
+ fixture.debugElement
+ .queryAll(By.directive(ButtonCloseDirective))
+ .map(({ nativeElement }) => nativeElement.getAttribute('aria-label'));
+
+ beforeEach(async () => {
+ fixture = TestBed.createComponent(NamedButtonCloseComponent);
+ await fixture.whenStable();
+ });
+
+ it('should keep the aria-label of the page', async () => {
+ expect(names()).toEqual(['Fechar', 'Fechar', 'Fechar']);
+ fixture.componentInstance.label.set('Cerrar');
+ await fixture.whenStable();
+ expect(names()).toEqual(['Fechar', 'Cerrar', 'Cerrar']);
+ });
+
+ it('should drop the default when the page binds null', async () => {
+ fixture.componentInstance.label.set(null);
+ await fixture.whenStable();
+ expect(names()).toEqual(['Fechar', null, null]);
+ });
});
diff --git a/projects/coreui-angular/src/lib/button/button-close.directive.ts b/projects/coreui-angular/src/lib/button/button-close.directive.ts
index f7355b27..2dce4964 100644
--- a/projects/coreui-angular/src/lib/button/button-close.directive.ts
+++ b/projects/coreui-angular/src/lib/button/button-close.directive.ts
@@ -7,6 +7,7 @@ import { ButtonDirective } from './button.directive';
hostDirectives: [{ directive: ThemeDirective, inputs: ['dark'] }],
host: {
class: 'btn btn-close',
+ 'aria-label': 'Close',
'[class]': 'hostClasses()',
'[aria-disabled]': 'ariaDisabled()',
'[aria-pressed]': 'isActive()',