Skip to content

Commit

Permalink
fix(alert): Add alert-dismissible class
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkoOleksiyenko committed Nov 27, 2023
1 parent a081136 commit 16d8c1f
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 15 deletions.
8 changes: 6 additions & 2 deletions angular/lib/src/lib/alert/alert.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class AlertStructureDirective {
<ng-template [auSlot]="state.slotDefault" [auSlotProps]="{state, widget}"></ng-template>
</div>
@if (state.dismissible) {
<button type="button" class="btn-close ms-auto" (click)="widget.api.close()" [attr.aria-label]="state.ariaCloseButtonLabel"></button>
<button type="button" class="btn-close" (click)="widget.api.close()" [attr.aria-label]="state.ariaCloseButtonLabel"></button>
}
</ng-template>`,
})
Expand All @@ -74,7 +74,11 @@ const defaultConfig: Partial<AlertProps> = {
</ng-template>
@if (!state().hidden) {
<div [auUse]="widget.directives.transitionDirective" class="au-alert alert alert-{{ state().type }} {{ state().className }}" role="alert">
<div
[auUse]="widget.directives.transitionDirective"
class="au-alert alert alert-{{ state().type }} {{ state().className }} {{ state().dismissible ? 'alert-dismissible' : '' }}"
role="alert"
>
<ng-template [auSlot]="state().slotStructure" [auSlotProps]="{state: state(), widget}"></ng-template>
</div>
}`,
Expand Down
2 changes: 2 additions & 0 deletions e2e/alert/alert.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ test.describe(`Alert tests`, () => {
await alertDemoPO.locatorRoot.waitFor();

await expect(alertPO.locatorRoot).toHaveClass(/alert-success/);
await expect(alertPO.locatorRoot).toHaveClass(/alert-dismissible/);

await alertPO.locatorCloseButton.click();

Expand All @@ -22,6 +23,7 @@ test.describe(`Alert tests`, () => {
await alertDemoPO.locatorShowAlertButton.click();

await expect(alertPO.locatorRoot).toHaveClass(/alert-danger/);
await expect(alertPO.locatorRoot).not.toHaveClass(/alert-dismissible/);
await expect(alertPO.locatorCloseButton).toHaveCount(0);
});

Expand Down
4 changes: 2 additions & 2 deletions e2e/samplesMarkup.e2e-spec.ts-snapshots/alert-config.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
<br />
<br />
<div
class="alert alert-success au-alert show"
class="alert alert-dismissible alert-success au-alert show"
role="alert"
>
<div
Expand All @@ -122,7 +122,7 @@
</div>
<button
aria-label="Close"
class="btn-close ms-auto"
class="btn-close"
type="button"
/>
</div>
Expand Down
4 changes: 2 additions & 2 deletions e2e/samplesMarkup.e2e-spec.ts-snapshots/alert-playground.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
class="container p-3"
>
<div
class="alert alert-primary au-alert show"
class="alert alert-dismissible alert-primary au-alert show"
role="alert"
>
<div
class="alert-body"
/>
<button
aria-label="Close"
class="btn-close ms-auto"
class="btn-close"
type="button"
/>
</div>
Expand Down
13 changes: 6 additions & 7 deletions react/lib/Alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ const DefaultSlotStructure = (slotContext: AlertContext) => (
<Slot slotContent={slotContext.state.slotDefault} props={slotContext}></Slot>
</div>
{slotContext.state.dismissible ? (
<button
type="button"
className="btn-close ms-auto"
onClick={slotContext.widget.api.close}
aria-label={slotContext.state.ariaCloseButtonLabel}
></button>
<button type="button" className="btn-close" onClick={slotContext.widget.api.close} aria-label={slotContext.state.ariaCloseButtonLabel}></button>
) : null}
</>
);
Expand All @@ -35,7 +30,11 @@ export const Alert = forwardRef(function Alert(props: PropsWithChildren<Partial<
return (
<>
{state.hidden ? null : (
<div className={`au-alert alert alert-${state.type} ${state.className}`} role="alert" ref={refTransition}>
<div
className={`au-alert alert alert-${state.type} ${state.className} ${state.dismissible ? 'alert-dismissible' : ''}`}
role="alert"
ref={refTransition}
>
<Slot slotContent={state.slotStructure} props={slotContext}></Slot>
</div>
)}
Expand Down
6 changes: 5 additions & 1 deletion svelte/lib/alert/Alert.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@
</script>

{#if !$hidden$}
<div class="au-alert alert alert-{$state$.type} {$state$.className}" role="alert" use:transitionDirective>
<div
class="au-alert alert alert-{$state$.type} {$state$.className} {$state$.dismissible ? 'alert-dismissible' : ''}"
role="alert"
use:transitionDirective
>
<Slot slotContent={$slotStructure$} props={slotContext} let:component let:props>
<slot slot="slot" name="structure" let:props {...props} />
<svelte:component this={component} {...props}>
Expand Down
2 changes: 1 addition & 1 deletion svelte/lib/alert/AlertDefaultStructure.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
</Slot>
</div>
{#if state.dismissible}
<button type="button" class="btn-close ms-auto" on:click={() => widget.api.close()} aria-label={state.ariaCloseButtonLabel} />
<button type="button" class="btn-close" on:click={() => widget.api.close()} aria-label={state.ariaCloseButtonLabel} />
{/if}

0 comments on commit 16d8c1f

Please sign in to comment.