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

fixed an issue caused by autowidth #557

Merged
merged 2 commits into from
Aug 23, 2023
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
57 changes: 32 additions & 25 deletions packages/uui-input/lib/uui-input.element.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FormControlMixin, LabelMixin } from '@umbraco-ui/uui-base/lib/mixins';
import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
import { css, html, LitElement, nothing, PropertyValueMap } from 'lit';
import { css, html, LitElement, PropertyValueMap } from 'lit';
import { property, query } from 'lit/decorators.js';
import { ifDefined } from 'lit/directives/if-defined.js';

Expand Down Expand Up @@ -401,34 +401,41 @@ export class UUIInputElement extends FormControlMixin(
render() {
return html`
${this.renderPrepend()}
<div id="control">
<input
id="input"
.type=${this.type}
.value=${this.value as string}
.name=${this.name}
pattern=${ifDefined(this.pattern)}
min=${ifDefined(this.min)}
max=${ifDefined(this.max)}
step=${ifDefined(this.step)}
spellcheck=${this.spellcheck}
autocomplete=${ifDefined(this.autocomplete as any)}
placeholder=${ifDefined(this.placeholder)}
aria-label=${ifDefined(this.label)}
inputmode=${ifDefined(this.inputMode)}
?disabled=${this.disabled}
?autofocus=${this.autofocus}
?required=${this.required}
?readonly=${this.readonly}
@input=${this.onInput}
@change=${this.onChange} />
${this.autoWidth ? this.renderAutoWidth() : nothing}
</div>
${this.autoWidth ? this.renderInputWithAutoWidth() : this.renderInput()}
${this.renderAppend()}
`;
}

private renderAutoWidth() {
private renderInputWithAutoWidth() {
html`<div id="control">
${this.renderInput()}${this.renderAutoWidthBackground()}
</div>`;
}

renderInput() {
return html`<input
id="input"
.type=${this.type}
.value=${this.value as string}
.name=${this.name}
pattern=${ifDefined(this.pattern)}
min=${ifDefined(this.min)}
max=${ifDefined(this.max)}
step=${ifDefined(this.step)}
spellcheck=${this.spellcheck}
autocomplete=${ifDefined(this.autocomplete as any)}
placeholder=${ifDefined(this.placeholder)}
aria-label=${ifDefined(this.label)}
inputmode=${ifDefined(this.inputMode)}
?disabled=${this.disabled}
?autofocus=${this.autofocus}
?required=${this.required}
?readonly=${this.readonly}
@input=${this.onInput}
@change=${this.onChange} />`;
}

private renderAutoWidthBackground() {
return html` <div id="auto" aria-hidden="true">${this.renderText()}</div>`;
}

Expand Down