Skip to content

Commit 714359c

Browse files
committed
feat(input-otp): add helper and error text, input label formatter, and keyboard focus ring
1 parent 240e9ae commit 714359c

18 files changed

Lines changed: 1020 additions & 24 deletions

File tree

‎core/api.txt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,10 @@ ion-input-otp,scoped
794794
ion-input-otp,prop,autocapitalize,string,'off',false,false
795795
ion-input-otp,prop,color,"danger" | "dark" | "light" | "medium" | "primary" | "secondary" | "success" | "tertiary" | "warning" | string & Record<never, never> | undefined,undefined,false,true
796796
ion-input-otp,prop,disabled,boolean,false,false,true
797+
ion-input-otp,prop,errorText,string | undefined,undefined,false,false
797798
ion-input-otp,prop,fill,"outline" | "solid" | undefined,'outline',false,false
799+
ion-input-otp,prop,helperText,string | undefined,undefined,false,false
800+
ion-input-otp,prop,inputLabelFormatter,((index: number, length: number) => string) | undefined,undefined,false,false
798801
ion-input-otp,prop,inputmode,"decimal" | "email" | "none" | "numeric" | "search" | "tel" | "text" | "url" | undefined,undefined,false,false
799802
ion-input-otp,prop,length,number,4,false,false
800803
ion-input-otp,prop,pattern,string | undefined,undefined,false,false

‎core/src/components.d.ts‎

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { ScrollBaseDetail, ScrollDetail } from "./components/content/content-int
1818
import { DatetimeChangeEventDetail, DatetimeHighlight, DatetimeHighlightCallback, DatetimeHourCycle, DatetimeParts, DatetimePresentation, FormatOptions, TitleSelectedDatesFormatter } from "./components/datetime/datetime-interface";
1919
import { SpinnerTypes } from "./components/spinner/spinner-configs";
2020
import { InputChangeEventDetail, InputInputEventDetail } from "./components/input/input-interface";
21-
import { InputOtpChangeEventDetail, InputOtpCompleteEventDetail, InputOtpInputEventDetail } from "./components/input-otp/input-otp-interface";
21+
import { InputOtpChangeEventDetail, InputOtpCompleteEventDetail, InputOtpInputEventDetail, InputOtpLabelFormatter } from "./components/input-otp/input-otp-interface";
2222
import { MenuChangeEventDetail, MenuCloseEventDetail, MenuType, Side } from "./components/menu/menu-interface";
2323
import { ModalBreakpointChangeEventDetail, ModalDragEventDetail, ModalHandleBehavior } from "./components/modal/modal-interface";
2424
import { NavComponent, NavComponentWithProps, NavOptions, RouterOutletOptions, SwipeGestureHandler, TransitionDoneFn, TransitionInstruction } from "./components/nav/nav-interface";
@@ -55,7 +55,7 @@ export { ScrollBaseDetail, ScrollDetail } from "./components/content/content-int
5555
export { DatetimeChangeEventDetail, DatetimeHighlight, DatetimeHighlightCallback, DatetimeHourCycle, DatetimeParts, DatetimePresentation, FormatOptions, TitleSelectedDatesFormatter } from "./components/datetime/datetime-interface";
5656
export { SpinnerTypes } from "./components/spinner/spinner-configs";
5757
export { InputChangeEventDetail, InputInputEventDetail } from "./components/input/input-interface";
58-
export { InputOtpChangeEventDetail, InputOtpCompleteEventDetail, InputOtpInputEventDetail } from "./components/input-otp/input-otp-interface";
58+
export { InputOtpChangeEventDetail, InputOtpCompleteEventDetail, InputOtpInputEventDetail, InputOtpLabelFormatter } from "./components/input-otp/input-otp-interface";
5959
export { MenuChangeEventDetail, MenuCloseEventDetail, MenuType, Side } from "./components/menu/menu-interface";
6060
export { ModalBreakpointChangeEventDetail, ModalDragEventDetail, ModalHandleBehavior } from "./components/modal/modal-interface";
6161
export { NavComponent, NavComponentWithProps, NavOptions, RouterOutletOptions, SwipeGestureHandler, TransitionDoneFn, TransitionInstruction } from "./components/nav/nav-interface";
@@ -1468,11 +1468,23 @@ export namespace Components {
14681468
* @default false
14691469
*/
14701470
"disabled": boolean;
1471+
/**
1472+
* Text that is placed under the input boxes and displayed when an error is detected.
1473+
*/
1474+
"errorText"?: string;
14711475
/**
14721476
* The fill for the input boxes. If `"solid"` the input boxes will have a background. If `"outline"` the input boxes will be transparent with a border.
14731477
* @default 'outline'
14741478
*/
14751479
"fill"?: 'outline' | 'solid';
1480+
/**
1481+
* Text that is placed under the input boxes and displayed when no error is detected.
1482+
*/
1483+
"helperText"?: string;
1484+
/**
1485+
* A callback used to format the accessible name of each input box. It receives the 0-based `index` of the box and the total `length`. By default the name is "Input 1 of 4", or "PIN, 1 of 4" with an `aria-label` of "PIN". See https://ionicframework.com/docs/troubleshooting/runtime#accessing-this if you need to access `this` from within the callback.
1486+
*/
1487+
"inputLabelFormatter"?: InputOtpLabelFormatter;
14761488
/**
14771489
* A hint to the browser for which keyboard to display. Possible values: `"none"`, `"text"`, `"tel"`, `"url"`, `"email"`, `"numeric"`, `"decimal"`, and `"search"`. For numbers (type="number"): "numeric" For text (type="text"): "text"
14781490
*/
@@ -6628,11 +6640,23 @@ declare namespace LocalJSX {
66286640
* @default false
66296641
*/
66306642
"disabled"?: boolean;
6643+
/**
6644+
* Text that is placed under the input boxes and displayed when an error is detected.
6645+
*/
6646+
"errorText"?: string;
66316647
/**
66326648
* The fill for the input boxes. If `"solid"` the input boxes will have a background. If `"outline"` the input boxes will be transparent with a border.
66336649
* @default 'outline'
66346650
*/
66356651
"fill"?: 'outline' | 'solid';
6652+
/**
6653+
* Text that is placed under the input boxes and displayed when no error is detected.
6654+
*/
6655+
"helperText"?: string;
6656+
/**
6657+
* A callback used to format the accessible name of each input box. It receives the 0-based `index` of the box and the total `length`. By default the name is "Input 1 of 4", or "PIN, 1 of 4" with an `aria-label` of "PIN". See https://ionicframework.com/docs/troubleshooting/runtime#accessing-this if you need to access `this` from within the callback.
6658+
*/
6659+
"inputLabelFormatter"?: InputOtpLabelFormatter;
66366660
/**
66376661
* A hint to the browser for which keyboard to display. Possible values: `"none"`, `"text"`, `"tel"`, `"url"`, `"email"`, `"numeric"`, `"decimal"`, and `"search"`. For numbers (type="number"): "numeric" For text (type="text"): "text"
66386662
*/
@@ -9236,7 +9260,9 @@ declare namespace LocalJSX {
92369260
"autocapitalize": string;
92379261
"color": Color;
92389262
"disabled": boolean;
9263+
"errorText": string;
92399264
"fill": 'outline' | 'solid';
9265+
"helperText": string;
92409266
"inputmode": 'none' | 'text' | 'tel' | 'url' | 'email' | 'numeric' | 'decimal' | 'search';
92419267
"length": number;
92429268
"pattern": string;

‎core/src/components/input-otp/input-otp-interface.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export interface InputOtpCompleteEventDetail {
1717
event?: Event;
1818
}
1919

20+
export type InputOtpLabelFormatter = (index: number, length: number) => string;
21+
2022
export interface InputOtpCustomEvent<T = InputOtpChangeEventDetail> extends CustomEvent {
2123
detail: T;
2224
target: HTMLIonInputOtpElement;

‎core/src/components/input-otp/input-otp.ios.scss‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
// --------------------------------------------------
1717

1818
:host(.input-otp-fill-outline) {
19-
--border-color: #{$item-ios-border-color};
19+
--internal-border-color: #{$item-ios-border-color};
2020
}

‎core/src/components/input-otp/input-otp.md.scss‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
// --------------------------------------------------
1717

1818
:host(.input-otp-fill-outline) {
19-
--border-color: #{$background-color-step-300};
19+
--internal-border-color: #{$background-color-step-300};
2020
}

‎core/src/components/input-otp/input-otp.scss‎

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@
6363
*/
6464
--highlight-color: var(--highlight-color-focused);
6565

66+
// Don't inherit `--border-color` from ancestors like `ion-modal`
67+
--border-color: initial;
68+
6669
display: block;
6770
position: relative;
6871

@@ -102,7 +105,9 @@
102105

103106
border-width: var(--border-width);
104107
border-style: solid;
105-
border-color: var(--border-color);
108+
// The defaults use `--internal-border-color` since a host
109+
// selector can't beat `:host(.input-otp-fill-*)`
110+
border-color: var(--border-color, var(--internal-border-color));
106111

107112
background: var(--background);
108113
color: var(--color);
@@ -134,6 +139,37 @@
134139
display: none;
135140
}
136141

142+
// Input Hint Text
143+
// ----------------------------------------------------------------
144+
145+
.input-otp-bottom {
146+
font-size: dynamic-font(12px);
147+
148+
line-height: dynamic-font(20px);
149+
150+
text-align: center;
151+
}
152+
153+
.input-otp-bottom .error-text {
154+
display: none;
155+
156+
color: var(--highlight-color-invalid);
157+
}
158+
159+
.input-otp-bottom .helper-text {
160+
display: block;
161+
162+
color: $text-color-step-300;
163+
}
164+
165+
:host(.ion-touched.ion-invalid) .input-otp-bottom .error-text {
166+
display: block;
167+
}
168+
169+
:host(.ion-touched.ion-invalid) .input-otp-bottom .helper-text {
170+
display: none;
171+
}
172+
137173
// Input Separator
138174
// ----------------------------------------------------------------
139175

@@ -198,7 +234,7 @@
198234
}
199235

200236
:host(.input-otp-fill-solid) {
201-
--border-color: #{$background-color-step-50};
237+
--internal-border-color: #{$background-color-step-50};
202238
--background: #{$background-color-step-50};
203239
}
204240

@@ -211,7 +247,7 @@
211247

212248
:host(.input-otp-fill-outline.input-otp-disabled) {
213249
--background: #{$background-color-step-50};
214-
--border-color: #{$background-color-step-100};
250+
--internal-border-color: #{$background-color-step-100};
215251
}
216252

217253
:host(.input-otp-disabled),
@@ -225,13 +261,19 @@
225261
outline: none;
226262
}
227263

264+
// The outline skips the validation colors since green fails 3:1 contrast
265+
:host(.has-focus.input-otp-keyboard-focus) .native-input:focus {
266+
outline: 2px solid var(--highlight-color-focused);
267+
outline-offset: 2px;
268+
}
269+
228270
:host(.input-otp-fill-outline.input-otp-readonly) {
229271
--background: #{$background-color-step-50};
230272
}
231273

232274
:host(.input-otp-fill-solid.input-otp-disabled),
233275
:host(.input-otp-fill-solid.input-otp-readonly) {
234-
--border-color: #{$background-color-step-100};
276+
--internal-border-color: #{$background-color-step-100};
235277
--background: #{$background-color-step-100};
236278
}
237279

0 commit comments

Comments
 (0)