Skip to content

Commit

Permalink
refactor(alert): simplify setFocus method (#10448)
Browse files Browse the repository at this point in the history
**Related Issue:** #6059

## Summary


- remove use of `getSlotted` utility
- simplify setFocus method focusing
- existing tests should suffice
  • Loading branch information
driskull authored and benelan committed Feb 8, 2025
1 parent d4589a7 commit 312ce19
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions packages/calcite-components/src/components/alert/alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
Watch,
} from "@stencil/core";
import {
getSlotted,
focusFirstTabbable,
setRequestedIcon,
slotChangeHasAssignedElement,
toAriaBoolean,
Expand Down Expand Up @@ -308,7 +308,6 @@ export class Alert implements OpenCloseComponent, LoadableComponent, T9nComponen
onClick={this.closeAlert}
onFocusin={this.autoClose ? this.handleKeyBoardFocus : null}
onFocusout={this.autoClose ? this.handleKeyBoardBlur : null}
ref={(el) => (this.closeButton = el)}
type="button"
>
<calcite-icon icon="x" scale={getIconScale(this.scale)} />
Expand Down Expand Up @@ -384,16 +383,7 @@ export class Alert implements OpenCloseComponent, LoadableComponent, T9nComponen
@Method()
async setFocus(): Promise<void> {
await componentFocusable(this);

const alertLinkEl: HTMLCalciteLinkElement = getSlotted(this.el, { selector: "calcite-link" });

if (!this.closeButton && !alertLinkEl) {
return;
} else if (alertLinkEl) {
return alertLinkEl.setFocus();
} else if (this.closeButton) {
this.closeButton.focus();
}
focusFirstTabbable(this.el);
}

//--------------------------------------------------------------------------
Expand Down Expand Up @@ -435,8 +425,6 @@ export class Alert implements OpenCloseComponent, LoadableComponent, T9nComponen

private autoCloseTimeoutId: number = null;

private closeButton: HTMLButtonElement;

private initialOpenTime: number;

private lastMouseOverBegin: number;
Expand Down

0 comments on commit 312ce19

Please sign in to comment.