Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(alert): simplify setFocus method #10448

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading