Skip to content

Commit 3b875ea

Browse files
asynclizcopybara-github
authored andcommitted
chore(button): remove lit static
Part of a chain of changes needed to support text wrapping and host aria PiperOrigin-RevId: 580969975
1 parent a2b3204 commit 3b875ea

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

button/internal/button.ts

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import '../../ripple/ripple.js';
99

1010
import {html, isServer, LitElement, nothing} from 'lit';
1111
import {property, query, queryAssignedElements} from 'lit/decorators.js';
12-
import {literal, html as staticHtml} from 'lit/static-html.js';
1312

1413
import {ARIAMixinStrict} from '../../internal/aria/aria.js';
1514
import {requestUpdateOnAriaChange} from '../../internal/aria/delegate.js';
@@ -118,28 +117,40 @@ export abstract class Button extends buttonBaseClass implements FormSubmitter {
118117
}
119118

120119
protected override render() {
121-
// Link buttons may not be disabled
122-
const isDisabled = this.disabled && !this.href;
123-
124-
const button = this.href ? literal`a` : literal`button`;
125-
// Needed for closure conformance
126-
const {ariaLabel, ariaHasPopup, ariaExpanded} = this as ARIAMixinStrict;
127-
return staticHtml`
128-
<${button}
129-
class="button"
130-
?disabled=${isDisabled}
131-
aria-label="${ariaLabel || nothing}"
132-
aria-haspopup="${ariaHasPopup || nothing}"
133-
aria-expanded="${ariaExpanded || nothing}"
134-
href=${this.href || nothing}
135-
target=${this.target || nothing}
136-
>${this.renderContent()}</${button}>`;
120+
return this.href ? this.renderLink() : this.renderButton();
137121
}
138122

139123
protected renderElevation?(): unknown;
140124

141125
protected renderOutline?(): unknown;
142126

127+
private renderButton() {
128+
// Needed for closure conformance
129+
const {ariaLabel, ariaHasPopup, ariaExpanded} = this as ARIAMixinStrict;
130+
return html`<button
131+
id="button"
132+
class="button"
133+
?disabled=${this.disabled}
134+
aria-label="${ariaLabel || nothing}"
135+
aria-haspopup="${ariaHasPopup || nothing}"
136+
aria-expanded="${ariaExpanded || nothing}">
137+
${this.renderContent()}
138+
</button>`;
139+
}
140+
141+
private renderLink() {
142+
// Needed for closure conformance
143+
const {ariaLabel} = this as ARIAMixinStrict;
144+
return html`<a
145+
id="link"
146+
class="button"
147+
aria-label="${ariaLabel || nothing}"
148+
href=${this.href}
149+
target=${this.target || nothing}
150+
>${this.renderContent()}
151+
</a>`;
152+
}
153+
143154
private renderContent() {
144155
// Link buttons may not be disabled
145156
const isDisabled = this.disabled && !this.href;

0 commit comments

Comments
 (0)