diff --git a/core/src/components.d.ts b/core/src/components.d.ts index 4b5a222fc83..9f71cd40a9c 100644 --- a/core/src/components.d.ts +++ b/core/src/components.d.ts @@ -1205,10 +1205,12 @@ export namespace Components { "color"?: Color; /** * If `true`, a character counter will display the ratio of characters used and the total character limit. Only applies when the `maxlength` property is set on the inner `ion-input` or `ion-textarea`. + * @deprecated Use the `counter` property on `ion-input` or `ion-textarea` instead. */ "counter": boolean; /** * A callback used to format the counter text. By default the counter text is set to "itemLength / maxLength". + * @deprecated Use the `counterFormatter` property on `ion-input` or `ion-textarea` instead. */ "counterFormatter"?: CounterFormatter; /** @@ -5055,10 +5057,12 @@ declare namespace LocalJSX { "color"?: Color; /** * If `true`, a character counter will display the ratio of characters used and the total character limit. Only applies when the `maxlength` property is set on the inner `ion-input` or `ion-textarea`. + * @deprecated Use the `counter` property on `ion-input` or `ion-textarea` instead. */ "counter"?: boolean; /** * A callback used to format the counter text. By default the counter text is set to "itemLength / maxLength". + * @deprecated Use the `counterFormatter` property on `ion-input` or `ion-textarea` instead. */ "counterFormatter"?: CounterFormatter; /** diff --git a/core/src/components/input/input.md.scss b/core/src/components/input/input.md.scss index c65da943cc3..6e58b9deae8 100644 --- a/core/src/components/input/input.md.scss +++ b/core/src/components/input/input.md.scss @@ -31,3 +31,9 @@ background-size: $input-md-input-clear-icon-size; } + +// Input Max Length Counter +// ---------------------------------------------------------------- +.input-bottom .counter { + letter-spacing: .0333333333em; +} diff --git a/core/src/components/input/input.scss b/core/src/components/input/input.scss index 80a62771693..b9db51ecc23 100644 --- a/core/src/components/input/input.scss +++ b/core/src/components/input/input.scss @@ -258,3 +258,21 @@ :host(.ion-invalid) .input-bottom .helper-text { display: none; } + +// Input Max Length Counter +// ---------------------------------------------------------------- + +.input-bottom .counter { + /** + * Counter should always be at + * the end of the container even + * when no helper/error texts are used. + */ + @include margin-horizontal(auto, null); + + color: #{$background-color-step-550}; + + white-space: nowrap; + + padding-inline-start: 16px; +} diff --git a/core/src/components/input/input.tsx b/core/src/components/input/input.tsx index 8f1d62935dd..e1e0198987a 100644 --- a/core/src/components/input/input.tsx +++ b/core/src/components/input/input.tsx @@ -17,6 +17,8 @@ import type { Attributes } from '../../utils/helpers'; import { inheritAriaAttributes, debounceEvent, findItemLabel, inheritAttributes } from '../../utils/helpers'; import { createColorClasses } from '../../utils/theme'; +import { getCounterText } from './input.utils'; + /** * @virtualProp {"ios" | "md"} mode - The mode determines which platform styles to use. */ @@ -521,20 +523,35 @@ export class Input implements ComponentInterface { return [