Skip to content

Commit

Permalink
fix(input): set native input id from name prop value (#370)
Browse files Browse the repository at this point in the history
Fallback to `id="input"` if no name value has been provided.
  • Loading branch information
dgonzalezr authored Jul 19, 2023
1 parent 028fc00 commit f88bfe6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const meta: Meta = {
maxlength: undefined,
min: undefined,
minlength: undefined,
name: 'input',
name: 'bq-input',
pattern: undefined,
readonly: false,
required: false,
Expand Down Expand Up @@ -196,11 +196,11 @@ export const ValidationStatus: Story = {
render: (args) => html`
<div class="flex flex-col gap-l">
<!-- Error -->
${Template({ ...args, 'validation-status': 'error' })}
${Template({ ...args, name: 'bq-input-error', 'validation-status': 'error' })}
<!-- Succes -->
${Template({ ...args, 'validation-status': 'success' })}
${Template({ ...args, name: 'bq-input-success', 'validation-status': 'success' })}
<!-- Warning -->
${Template({ ...args, 'validation-status': 'warning' })}
${Template({ ...args, name: 'bq-input-warning', 'validation-status': 'warning' })}
</div>
`,
args: {
Expand Down
5 changes: 3 additions & 2 deletions packages/bee-q/src/components/input/bq-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class BqInput {
private suffixElem?: HTMLElement;

private debounceBqInput: TDebounce<void>;
private fallbackInputId = 'input';

// Reference to host HTML element
// ===================================
Expand Down Expand Up @@ -301,7 +302,7 @@ export class BqInput {
{/* Label */}
<label
class={{ 'bq-input--label': true, hidden: !this.hasLabel }}
htmlFor="input"
htmlFor={this.name || this.fallbackInputId}
ref={(labelElem) => (this.labelElem = labelElem)}
part="label"
>
Expand All @@ -326,7 +327,7 @@ export class BqInput {
</span>
{/* HTML Input */}
<input
id="input"
id={this.name || this.fallbackInputId}
class="bq-input--control__input"
aria-disabled={this.disabled ? 'true' : 'false'}
autoCapitalize={this.autocapitalize}
Expand Down

0 comments on commit f88bfe6

Please sign in to comment.