Skip to content

Commit

Permalink
fix(input, input-number, input-text): restore autofocus, `enter-key…
Browse files Browse the repository at this point in the history
…-mode` and `input-mode` attributes (#9245)

**Related Issue:** #9235

## Summary

This fixes the following issues introduced by #9123 when component props
that shadowed global attributes were removed:

* the kebab-cased attribute names of those props would no longer work
(namely, `enter-key-mode`, `input-mode`)
* `autofocus` was missing from component types as Stencil does not
include it in the base `HTMLAttribute` type (see
ionic-team/stencil#5726).
  • Loading branch information
jcfranco committed May 10, 2024
1 parent 1ad530e commit 2542f4e
Show file tree
Hide file tree
Showing 8 changed files with 245 additions and 17 deletions.
84 changes: 84 additions & 0 deletions packages/calcite-components/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2034,6 +2034,10 @@ export namespace Components {
* @mdn [step](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete)
*/
"autocomplete": string;
/**
* Adds global prop, missing from Stencil's `HTMLElement` type, see https://github.com/ionic-team/stencil/issues/5726
*/
"autofocus": boolean;
/**
* When `true`, a clear button is displayed when the component has a value. The clear button shows by default for `"search"`, `"time"`, and `"date"` types, and will not display for the `"textarea"` type.
*/
Expand All @@ -2044,6 +2048,11 @@ export namespace Components {
*/
"disabled": boolean;
"editingEnabled": boolean;
/**
* Adds support for kebab-cased attribute, removed in https://github.com/Esri/calcite-design-system/pull/9123
* @futureBreaking kebab-cased attribute will not be supported in a future release
*/
"enterKeyHint": string;
/**
* When `type` is `"file"`, specifies the component's selected files.
* @mdn https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/files
Expand All @@ -2065,6 +2074,11 @@ export namespace Components {
* When `true`, the icon will be flipped when the element direction is right-to-left (`"rtl"`).
*/
"iconFlipRtl": boolean;
/**
* Adds support for kebab-cased attribute, removed in https://github.com/Esri/calcite-design-system/pull/9123
* @futureBreaking kebab-cased attribute will not be supported in a future release
*/
"inputMode": string;
/**
* Accessible name for the component.
*/
Expand Down Expand Up @@ -2364,6 +2378,10 @@ export namespace Components {
* @mdn [step](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete)
*/
"autocomplete": string;
/**
* Adds global prop, missing from Stencil's `HTMLElement` type, see https://github.com/ionic-team/stencil/issues/5726
*/
"autofocus": boolean;
/**
* When `true`, a clear button is displayed when the component has a value.
*/
Expand All @@ -2374,6 +2392,11 @@ export namespace Components {
*/
"disabled": boolean;
"editingEnabled": boolean;
/**
* Adds support for kebab-cased attribute, removed in https://github.com/Esri/calcite-design-system/pull/9123
* @futureBreaking kebab-cased attribute will not be supported in a future release
*/
"enterKeyHint": string;
/**
* The `id` of the form that will be associated with the component. When not set, the component will be associated with its ancestor form element, if any.
*/
Expand All @@ -2391,6 +2414,11 @@ export namespace Components {
* When `true`, the icon will be flipped when the element direction is right-to-left (`"rtl"`).
*/
"iconFlipRtl": boolean;
/**
* Adds support for kebab-cased attribute, removed in https://github.com/Esri/calcite-design-system/pull/9123
* @futureBreaking kebab-cased attribute will not be supported in a future release
*/
"inputMode": string;
/**
* When `true`, restricts the component to integer numbers only and disables exponential notation.
*/
Expand Down Expand Up @@ -2522,6 +2550,10 @@ export namespace Components {
* @mdn [step](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete)
*/
"autocomplete": string;
/**
* Adds global prop, missing from Stencil's `HTMLElement` type, see https://github.com/ionic-team/stencil/issues/5726
*/
"autofocus": boolean;
/**
* When `true`, a clear button is displayed when the component has a value.
*/
Expand All @@ -2532,6 +2564,11 @@ export namespace Components {
*/
"disabled": boolean;
"editingEnabled": boolean;
/**
* Adds support for kebab-cased attribute, removed in https://github.com/Esri/calcite-design-system/pull/9123
* @futureBreaking kebab-cased attribute will not be supported in a future release
*/
"enterKeyHint": string;
/**
* The `id` of the form that will be associated with the component. When not set, the component will be associated with its ancestor form element, if any.
*/
Expand All @@ -2545,6 +2582,11 @@ export namespace Components {
* When `true`, the icon will be flipped when the element direction is right-to-left (`"rtl"`).
*/
"iconFlipRtl": boolean;
/**
* Adds support for kebab-cased attribute, removed in https://github.com/Esri/calcite-design-system/pull/9123
* @futureBreaking kebab-cased attribute will not be supported in a future release
*/
"inputMode": string;
/**
* Accessible name for the component's button or hyperlink.
*/
Expand Down Expand Up @@ -9748,6 +9790,10 @@ declare namespace LocalJSX {
* @mdn [step](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete)
*/
"autocomplete"?: string;
/**
* Adds global prop, missing from Stencil's `HTMLElement` type, see https://github.com/ionic-team/stencil/issues/5726
*/
"autofocus"?: boolean;
/**
* When `true`, a clear button is displayed when the component has a value. The clear button shows by default for `"search"`, `"time"`, and `"date"` types, and will not display for the `"textarea"` type.
*/
Expand All @@ -9758,6 +9804,11 @@ declare namespace LocalJSX {
*/
"disabled"?: boolean;
"editingEnabled"?: boolean;
/**
* Adds support for kebab-cased attribute, removed in https://github.com/Esri/calcite-design-system/pull/9123
* @futureBreaking kebab-cased attribute will not be supported in a future release
*/
"enterKeyHint"?: string;
/**
* When `type` is `"file"`, specifies the component's selected files.
* @mdn https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/files
Expand All @@ -9779,6 +9830,11 @@ declare namespace LocalJSX {
* When `true`, the icon will be flipped when the element direction is right-to-left (`"rtl"`).
*/
"iconFlipRtl"?: boolean;
/**
* Adds support for kebab-cased attribute, removed in https://github.com/Esri/calcite-design-system/pull/9123
* @futureBreaking kebab-cased attribute will not be supported in a future release
*/
"inputMode"?: string;
/**
* Accessible name for the component.
*/
Expand Down Expand Up @@ -10091,6 +10147,10 @@ declare namespace LocalJSX {
* @mdn [step](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete)
*/
"autocomplete"?: string;
/**
* Adds global prop, missing from Stencil's `HTMLElement` type, see https://github.com/ionic-team/stencil/issues/5726
*/
"autofocus"?: boolean;
/**
* When `true`, a clear button is displayed when the component has a value.
*/
Expand All @@ -10101,6 +10161,11 @@ declare namespace LocalJSX {
*/
"disabled"?: boolean;
"editingEnabled"?: boolean;
/**
* Adds support for kebab-cased attribute, removed in https://github.com/Esri/calcite-design-system/pull/9123
* @futureBreaking kebab-cased attribute will not be supported in a future release
*/
"enterKeyHint"?: string;
/**
* The `id` of the form that will be associated with the component. When not set, the component will be associated with its ancestor form element, if any.
*/
Expand All @@ -10118,6 +10183,11 @@ declare namespace LocalJSX {
* When `true`, the icon will be flipped when the element direction is right-to-left (`"rtl"`).
*/
"iconFlipRtl"?: boolean;
/**
* Adds support for kebab-cased attribute, removed in https://github.com/Esri/calcite-design-system/pull/9123
* @futureBreaking kebab-cased attribute will not be supported in a future release
*/
"inputMode"?: string;
/**
* When `true`, restricts the component to integer numbers only and disables exponential notation.
*/
Expand Down Expand Up @@ -10251,6 +10321,10 @@ declare namespace LocalJSX {
* @mdn [step](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete)
*/
"autocomplete"?: string;
/**
* Adds global prop, missing from Stencil's `HTMLElement` type, see https://github.com/ionic-team/stencil/issues/5726
*/
"autofocus"?: boolean;
/**
* When `true`, a clear button is displayed when the component has a value.
*/
Expand All @@ -10261,6 +10335,11 @@ declare namespace LocalJSX {
*/
"disabled"?: boolean;
"editingEnabled"?: boolean;
/**
* Adds support for kebab-cased attribute, removed in https://github.com/Esri/calcite-design-system/pull/9123
* @futureBreaking kebab-cased attribute will not be supported in a future release
*/
"enterKeyHint"?: string;
/**
* The `id` of the form that will be associated with the component. When not set, the component will be associated with its ancestor form element, if any.
*/
Expand All @@ -10274,6 +10353,11 @@ declare namespace LocalJSX {
* When `true`, the icon will be flipped when the element direction is right-to-left (`"rtl"`).
*/
"iconFlipRtl"?: boolean;
/**
* Adds support for kebab-cased attribute, removed in https://github.com/Esri/calcite-design-system/pull/9123
* @futureBreaking kebab-cased attribute will not be supported in a future release
*/
"inputMode"?: string;
/**
* Accessible name for the component's button or hyperlink.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import {
import { getElementRect, getElementXY, selectText } from "../../tests/utils";
import { letterKeys, numberKeys } from "../../utils/key";
import { locales, numberStringFormatter } from "../../utils/locale";
import { testHiddenInputSyncing, testPostValidationFocusing } from "../input/common/tests";
import {
testWorkaroundForGlobalPropRemoval,
testHiddenInputSyncing,
testPostValidationFocusing,
} from "../input/common/tests";

describe("calcite-input-number", () => {
const delayFor2UpdatesInMs = 200;
Expand Down Expand Up @@ -1757,6 +1761,8 @@ describe("calcite-input-number", () => {
testHiddenInputSyncing("calcite-input-number");
});

testWorkaroundForGlobalPropRemoval("calcite-input-number");

describe("translation support", () => {
t9n("calcite-input-number");
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ export class InputNumber
/** Specifies the text alignment of the component's value. */
@Prop({ reflect: true }) alignment: Extract<"start" | "end", Alignment> = "start";

/**
* Adds global prop, missing from Stencil's `HTMLElement` type, see https://github.com/ionic-team/stencil/issues/5726
*
* @internal
*/
// eslint-disable-next-line @stencil-community/reserved-member-names
@Prop() autofocus: boolean;

/**
* When `true`, a clear button is displayed when the component has a value.
*/
Expand All @@ -136,6 +144,15 @@ export class InputNumber
this.setDisabledAction();
}

/**
* Adds support for kebab-cased attribute, removed in https://github.com/Esri/calcite-design-system/pull/9123
*
* @futureBreaking kebab-cased attribute will not be supported in a future release
* @internal
*/
// eslint-disable-next-line @stencil-community/reserved-member-names
@Prop() enterKeyHint: string;

/**
* The `id` of the form that will be associated with the component.
*
Expand All @@ -158,6 +175,15 @@ export class InputNumber
/** When `true`, the icon will be flipped when the element direction is right-to-left (`"rtl"`). */
@Prop({ reflect: true }) iconFlipRtl = false;

/**
* Adds support for kebab-cased attribute, removed in https://github.com/Esri/calcite-design-system/pull/9123
*
* @futureBreaking kebab-cased attribute will not be supported in a future release
* @internal
*/
// eslint-disable-next-line @stencil-community/reserved-member-names
@Prop() inputMode: string;

/** When `true`, restricts the component to integer numbers only and disables exponential notation. */
@Prop() integer = false;

Expand Down Expand Up @@ -1059,8 +1085,8 @@ export class InputNumber
autofocus={this.el.autofocus ? true : null}
defaultValue={this.defaultValue}
disabled={this.disabled ? true : null}
enterKeyHint={this.el.enterKeyHint}
inputMode={this.el.inputMode}
enterKeyHint={this.el.enterKeyHint || this.el.getAttribute("enterkeyhint")}
inputMode={this.el.inputMode || this.el.getAttribute("inputmode")}
key="localized-input"
maxLength={this.maxLength}
minLength={this.minLength}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import {
t9n,
} from "../../tests/commonTests";
import { selectText } from "../../tests/utils";
import { testHiddenInputSyncing, testPostValidationFocusing } from "../input/common/tests";
import {
testHiddenInputSyncing,
testPostValidationFocusing,
testWorkaroundForGlobalPropRemoval,
} from "../input/common/tests";

describe("calcite-input-text", () => {
describe("labelable", () => {
Expand Down Expand Up @@ -469,6 +473,8 @@ describe("calcite-input-text", () => {
testHiddenInputSyncing("calcite-input-text");
});

testWorkaroundForGlobalPropRemoval("calcite-input-text");

describe("translation support", () => {
t9n("calcite-input-text");
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ export class InputText
/** Specifies the text alignment of the component's value. */
@Prop({ reflect: true }) alignment: Extract<"start" | "end", Alignment> = "start";

/**
* Adds global prop, missing from Stencil's `HTMLElement` type, see https://github.com/ionic-team/stencil/issues/5726
*
* @internal
*/
// eslint-disable-next-line @stencil-community/reserved-member-names
@Prop() autofocus: boolean;

/**
* When `true`, a clear button is displayed when the component has a value.
*/
Expand All @@ -112,6 +120,15 @@ export class InputText
this.setDisabledAction();
}

/**
* Adds support for kebab-cased attribute, removed in https://github.com/Esri/calcite-design-system/pull/9123
*
* @futureBreaking kebab-cased attribute will not be supported in a future release
* @internal
*/
// eslint-disable-next-line @stencil-community/reserved-member-names
@Prop() enterKeyHint: string;

/**
* The `id` of the form that will be associated with the component.
*
Expand All @@ -130,6 +147,15 @@ export class InputText
/** When `true`, the icon will be flipped when the element direction is right-to-left (`"rtl"`). */
@Prop({ reflect: true }) iconFlipRtl = false;

/**
* Adds support for kebab-cased attribute, removed in https://github.com/Esri/calcite-design-system/pull/9123
*
* @futureBreaking kebab-cased attribute will not be supported in a future release
* @internal
*/
// eslint-disable-next-line @stencil-community/reserved-member-names
@Prop() inputMode: string;

/** Accessible name for the component's button or hyperlink. */
@Prop() label: string;

Expand Down Expand Up @@ -632,7 +658,6 @@ export class InputText
/>
);
const prefixText = <div class={CSS.prefix}>{this.prefixText}</div>;

const suffixText = <div class={CSS.suffix}>{this.suffixText}</div>;

const childEl = (
Expand All @@ -646,8 +671,8 @@ export class InputText
}}
defaultValue={this.defaultValue}
disabled={this.disabled ? true : null}
enterKeyHint={this.el.enterKeyHint}
inputMode={this.el.inputMode}
enterKeyHint={this.el.enterKeyHint || this.el.getAttribute("enterkeyhint")}
inputMode={this.el.inputMode || this.el.getAttribute("inputmode")}
maxLength={this.maxLength}
minLength={this.minLength}
name={this.name}
Expand Down

0 comments on commit 2542f4e

Please sign in to comment.