Skip to content
Open
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
28 changes: 9 additions & 19 deletions iconbutton/internal/icon-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import '../../focus/md-focus-ring.js';
import '../../ripple/ripple.js';

import {html, isServer, LitElement, nothing} from 'lit';
import {property, state} from 'lit/decorators.js';
import {html, LitElement, nothing} from 'lit';
import {property, query, state} from 'lit/decorators.js';
import {classMap} from 'lit/directives/class-map.js';
import {literal, html as staticHtml} from 'lit/static-html.js';

Expand Down Expand Up @@ -144,10 +144,11 @@ export class IconButton extends iconButtonBaseClass implements FormSubmitter {

@state() private flipIcon = isRtl(this, this.flipIconInRtl);

constructor() {
super();
if (!isServer) {
this.addEventListener('click', this.handleClick.bind(this));
@query('.button') private readonly buttonElement!: HTMLElement | null;

override click() {
if (!this.disabled && this.buttonElement) {
this.buttonElement.click();
}
}

Expand Down Expand Up @@ -195,7 +196,7 @@ export class IconButton extends iconButtonBaseClass implements FormSubmitter {
const {ariaLabel} = this as ARIAMixinStrict;
return html`
<a
class="link"
class="link button"
id="link"
href="${this.href}"
download="${this.download || nothing}"
Expand All @@ -210,6 +211,7 @@ export class IconButton extends iconButtonBaseClass implements FormSubmitter {
return {
'flip-icon': this.flipIcon,
'selected': this.toggle && this.selected,
'button': !this.href
};
}

Expand Down Expand Up @@ -248,18 +250,6 @@ export class IconButton extends iconButtonBaseClass implements FormSubmitter {
super.connectedCallback();
}

/** Handles a click on this element. */
private handleClick(event: MouseEvent) {
// If the icon button is soft-disabled, we need to explicitly prevent the
// click from propagating to other event listeners as well as prevent the
// default action.
if (!this.href && this.softDisabled) {
event.stopImmediatePropagation();
event.preventDefault();
return;
}
}

/**
* Handles a click on the child <div> or <button> element within this
* element's shadow DOM.
Expand Down