Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 7 additions & 7 deletions src/ak-button/ak-button.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ export class Button extends LitElement implements IButton {

#internals = InternalsController.of(this, { role: "button" });

@property({ reflect: true, type: Boolean, attribute: "disabled" })
public _disabled = false;
@property({ reflect: true, type: Boolean })
disabled = false;

public get disabled() {
return this._disabled || this.#internals.formDisabled;
get #disabled() {
return this.matches(":disabled") || this.disabled;
}

private onClick = (event: MouseEvent) => {
Expand Down Expand Up @@ -196,7 +196,7 @@ export class Button extends LitElement implements IButton {
public willUpdate(changed: PropertyValues<this>): void {
super.willUpdate(changed);
this.#internals.ariaLabel = this.label || null;
this.#internals.ariaDisabled = String(!!this._disabled);
this.#internals.ariaDisabled = String(!!this.#disabled);
if (this.variant === "link" && this.href) {
this.tabIndex = -1;
} else {
Expand All @@ -205,8 +205,8 @@ export class Button extends LitElement implements IButton {
}

public override render() {
const { href, type, target, name, value, disabled, rel, download, onClick, onKeydown } =
this;
const { href, type, target, name, value, rel, download, onClick, onKeydown } = this;
const disabled = this.#disabled;

return this.variant === "link" && typeof href === "string"
? linkTemplate({ href, target, disabled, rel, download, onClick, onKeydown })
Expand Down
24 changes: 14 additions & 10 deletions src/ak-button/ak-button.css
Original file line number Diff line number Diff line change
Expand Up @@ -834,16 +834,6 @@
margin-inline-start: var(--button__icon--m-end--MarginLeft);
}

:host:disabled {
pointer-events: none;
color: var(--button--disabled--Color);
background-color: var(--button--disabled--BackgroundColor);
}

:host:disabled #main::after {
border-color: var(--button--disabled--after--BorderColor);
}

:host([variant="link"]:not[inline]):hover #main {
--button--m-link--Color: var(--button--m-link--hover--Color);
--button--m-link--BackgroundColor: var(--button--m-link--hover--BackgroundColor);
Expand Down Expand Up @@ -881,3 +871,17 @@
--button--m-danger--Color: var(--button--m-link--m-danger--Color);
--button--m-danger--BackgroundColor: var(--button--m-link--m-danger--BackgroundColor);
}

:is(:host:disabled, :host([disabled])) #main {
pointer-events: none;
color: var(--button--disabled--Color);
background-color: var(--button--disabled--BackgroundColor);
}

:is(:host:disabled, :host([disabled])) #main::after {
border-color: var(--button--disabled--after--BorderColor);
}

:is(:host:disabled, :host([disabled])) [part="anchor"] {
text-decoration: underline;
}
11 changes: 11 additions & 0 deletions src/ak-button/ak-button.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,17 @@ export const Link: Story = {
},
};

export const DisabledLink: Story = {
...template,
args: {
variant: "link",
href: "https://goauthentik.io",
target: "_blank",
disabled: true,
content: "Gerudo!",
},
};

export const InlineLink: Story = {
args: {
variant: "link",
Expand Down
2 changes: 1 addition & 1 deletion src/ak-button/ak-button.template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function linkTemplate(props: ButtonLinkProps) {
const { href, target, disabled, download, rel, onClick, onKeydown } = props;
return html`<a
id="main"
href=${href}
href=${ifDefined(disabled ? null : href)}
part="anchor"
target="${ifDefined(target)}"
?disabled=${disabled}
Expand Down