Skip to content

Commit d8851a5

Browse files
authored
fix(input): Removed overriden tabIndex property (#1836)
1 parent adf8a05 commit d8851a5

File tree

4 files changed

+29
-31
lines changed

4 files changed

+29
-31
lines changed

src/components/common/util.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isServer } from 'lit';
1+
import { isServer, nothing } from 'lit';
22

33
export const asPercent = (part: number, whole: number) => (part / whole) * 100;
44

@@ -581,3 +581,13 @@ export function toMerged<
581581
>(target: T, source: S): T & S {
582582
return merge(structuredClone(target), source);
583583
}
584+
585+
/**
586+
* Similar to Lit's `ifDefined` directive except one can check `assertion`
587+
* and bind a different `value` through this wrapper.
588+
*/
589+
export function bindIf<T>(assertion: unknown, value: T): NonNullable<T> {
590+
return assertion
591+
? (value ?? (nothing as NonNullable<T>))
592+
: (nothing as NonNullable<T>);
593+
}

src/components/file-input/file-input.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { html, nothing } from 'lit';
1+
import { html } from 'lit';
22
import { property, state } from 'lit/decorators.js';
3-
import { ifDefined } from 'lit/directives/if-defined.js';
43

54
import { addThemingController } from '../../theming/theming-controller.js';
65
import IgcButtonComponent from '../button/button.js';
@@ -10,7 +9,7 @@ import { EventEmitterMixin } from '../common/mixins/event-emitter.js';
109
import { FormValueFileListTransformers } from '../common/mixins/forms/form-transformers.js';
1110
import { createFormValueState } from '../common/mixins/forms/form-value.js';
1211
import { partMap } from '../common/part-map.js';
13-
import { isEmpty } from '../common/util.js';
12+
import { bindIf, isEmpty } from '../common/util.js';
1413
import {
1514
IgcInputBaseComponent,
1615
type IgcInputComponentEventMap,
@@ -126,12 +125,6 @@ export default class IgcFileInputComponent extends EventEmitterMixin<
126125
@property({ type: Boolean })
127126
public override autofocus!: boolean;
128127

129-
/**
130-
* @internal
131-
*/
132-
@property({ type: Number })
133-
public override tabIndex = 0;
134-
135128
/** @hidden */
136129
@property({ type: Boolean, attribute: false, noAccessor: true })
137130
public override readonly readOnly = false;
@@ -208,6 +201,9 @@ export default class IgcFileInputComponent extends EventEmitterMixin<
208201
}
209202

210203
protected renderInput() {
204+
const hasNegativeTabIndex = this.getAttribute('tabindex') === '-1';
205+
const hasHelperText = !isEmpty(this._helperText);
206+
211207
return html`
212208
<input
213209
id=${this.inputId}
@@ -217,11 +213,9 @@ export default class IgcFileInputComponent extends EventEmitterMixin<
217213
?required=${this.required}
218214
?autofocus=${this.autofocus}
219215
?multiple=${this.multiple}
220-
tabindex=${this.tabIndex}
221-
accept=${ifDefined(this.accept === '' ? undefined : this.accept)}
222-
aria-describedby=${ifDefined(
223-
isEmpty(this._helperText) ? nothing : 'helper-text'
224-
)}
216+
tabindex=${bindIf(hasNegativeTabIndex, -1)}
217+
accept=${bindIf(this.accept, this.accept)}
218+
aria-describedby=${bindIf(hasHelperText, 'helper-text')}
225219
@click=${this._handleClick}
226220
@change=${this._handleChange}
227221
@cancel=${this._handleCancel}

src/components/input/input.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { html, nothing } from 'lit';
1+
import { html } from 'lit';
22
import { property } from 'lit/decorators.js';
33
import { ifDefined } from 'lit/directives/if-defined.js';
44
import { live } from 'lit/directives/live.js';
55

66
import { registerComponent } from '../common/definitions/register.js';
77
import { createFormValueState } from '../common/mixins/forms/form-value.js';
88
import { partMap } from '../common/part-map.js';
9-
import { isEmpty } from '../common/util.js';
9+
import { bindIf, isEmpty } from '../common/util.js';
1010
import type { InputType, RangeTextSelectMode } from '../types.js';
1111
import IgcValidationContainerComponent from '../validation-container/validation-container.js';
1212
import { IgcInputBaseComponent } from './input-base.js';
@@ -199,12 +199,6 @@ export default class IgcInputComponent extends IgcInputBaseComponent {
199199
@property({ type: Boolean, reflect: true, attribute: 'validate-only' })
200200
public validateOnly = false;
201201

202-
/**
203-
* @internal
204-
*/
205-
@property({ type: Number })
206-
public override tabIndex = 0;
207-
208202
/* blazorSuppress */
209203
/** Replaces the selected text in the input. */
210204
public override setRangeText(
@@ -247,6 +241,9 @@ export default class IgcInputComponent extends IgcInputBaseComponent {
247241
}
248242

249243
protected renderInput() {
244+
const hasNegativeTabIndex = this.getAttribute('tabindex') === '-1';
245+
const hasHelperText = !isEmpty(this._helperText);
246+
250247
return html`
251248
<input
252249
id=${this.inputId}
@@ -260,17 +257,15 @@ export default class IgcInputComponent extends IgcInputBaseComponent {
260257
?disabled=${this.disabled}
261258
?required=${this.required}
262259
?autofocus=${this.autofocus}
263-
tabindex=${this.tabIndex}
260+
tabindex=${bindIf(hasNegativeTabIndex, -1)}
264261
autocomplete=${ifDefined(this.autocomplete as any)}
265262
inputmode=${ifDefined(this.inputMode)}
266-
min=${ifDefined(this.validateOnly ? undefined : this.min)}
267-
max=${ifDefined(this.validateOnly ? undefined : this.max)}
263+
min=${bindIf(!this.validateOnly, this.min)}
264+
max=${bindIf(!this.validateOnly, this.max)}
268265
minlength=${ifDefined(this.minLength)}
269-
maxlength=${ifDefined(this.validateOnly ? undefined : this.maxLength)}
266+
maxlength=${bindIf(!this.validateOnly, this.maxLength)}
270267
step=${ifDefined(this.step)}
271-
aria-describedby=${ifDefined(
272-
isEmpty(this._helperText) ? nothing : 'helper-text'
273-
)}
268+
aria-describedby=${bindIf(hasHelperText, 'helper-text')}
274269
@change=${this.handleChange}
275270
@input=${this.handleInput}
276271
@blur=${this._handleBlur}

src/components/select/select.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,6 @@ export default class IgcSelectComponent extends FormAssociatedRequiredMixin(
663663
aria-describedby="select-helper-text"
664664
aria-expanded=${this.open}
665665
exportparts="container: input, input: native-input, label, prefix, suffix"
666-
tabIndex=${this.disabled ? -1 : 0}
667666
value=${ifDefined(value)}
668667
placeholder=${ifDefined(this.placeholder)}
669668
label=${ifDefined(this.label)}

0 commit comments

Comments
 (0)