Skip to content

Commit 576f68b

Browse files
MariaLStefanjanivoBenPag
authored
fix(elements/ino-input): prevent label cut-off in outline variant (#1189)
* style(elements|ino-input): add padding to label * chore: add outline runtime change warning * fix: ino-input story type errors * use MDCNotchedOutline * fix notch of input * push build changes * revert to minimal changes * improve spacing * remove redundant css * feat: add mac special font scaling * fix mac issue * move label logic to ino-label * use correct lifecycle --------- Co-authored-by: Jan-Niklas Voß <jan-niklas.voss@inovex.de> Co-authored-by: Benjamin Pagelsdorf <bpagelsdorf@inovex.de>
1 parent b7eb49c commit 576f68b

File tree

10 files changed

+199
-45
lines changed

10 files changed

+199
-45
lines changed

packages/elements-angular/src/directives/proxies.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,8 @@ export declare interface InoInputFile extends Components.InoInputFile {
585585

586586

587587
@ProxyCmp({
588-
inputs: ['disabled', 'for', 'outline', 'required', 'showHint', 'text']
588+
inputs: ['disabled', 'for', 'outline', 'required', 'showHint', 'text'],
589+
methods: ['getMdcNotchedOutlineInstance']
589590
})
590591
@Component({
591592
selector: 'ino-label',

packages/elements/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"@material/tab-indicator": "^13.0.0",
7272
"@material/tab-scroller": "^13.0.0",
7373
"@material/textfield": "^13.0.0",
74+
"@material/notched-outline": "^13.0.0",
7475
"@material/typography": "^13.0.0",
7576
"@stencil/core": "^4.12.2",
7677
"@tarekraafat/autocomplete.js": "^10.2.7",

packages/elements/src/components.d.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import { HTMLStencilElement, JSXBase } from "@stencil/core/internal";
88
import { Alignment, ButtonType, ButtonVariants, ChipSurface, DialogCloseAction, DialogSubmitAction, HorizontalLocation, ImageDecodingTypes, InputType, KeyValue, Locations, NavDrawerAnchor, NavDrawerLabels, NavDrawerVariant, SnackbarLabels, SnackbarType, SpinnerType, TippyThemes, TooltipTrigger, UserInputInterceptor, VerticalLocation, ViewModeUnion } from "./components/types";
99
import { PickerTypeKeys } from "./components/ino-datepicker/picker-factory";
1010
import { Placement, Props } from "tippy.js";
11+
import { MDCNotchedOutline } from "@material/notched-outline";
1112
import { SortDirection, SortDirectionChangeDetails } from "./interface";
1213
export { Alignment, ButtonType, ButtonVariants, ChipSurface, DialogCloseAction, DialogSubmitAction, HorizontalLocation, ImageDecodingTypes, InputType, KeyValue, Locations, NavDrawerAnchor, NavDrawerLabels, NavDrawerVariant, SnackbarLabels, SnackbarType, SpinnerType, TippyThemes, TooltipTrigger, UserInputInterceptor, VerticalLocation, ViewModeUnion } from "./components/types";
1314
export { PickerTypeKeys } from "./components/ino-datepicker/picker-factory";
1415
export { Placement, Props } from "tippy.js";
16+
export { MDCNotchedOutline } from "@material/notched-outline";
1517
export { SortDirection, SortDirectionChangeDetails } from "./interface";
1618
export namespace Components {
1719
interface InoAccordion {
@@ -796,7 +798,7 @@ export namespace Components {
796798
*/
797799
"name"?: string;
798800
/**
799-
* Styles the input field as outlined element.
801+
* Styles the input field as outlined element. This property is immutable which means that it should not be changed after its first initialization. Changing this property at runtime causes problems in combination with the floating label. You can read more about this issue [here](https://github.com/inovex/elements/issues/1216).
800802
*/
801803
"outline"?: boolean;
802804
/**
@@ -906,6 +908,10 @@ export namespace Components {
906908
* Id of the associated form control
907909
*/
908910
"for": string;
911+
/**
912+
* Returns internal mdcNotchedOutline instance
913+
*/
914+
"getMdcNotchedOutlineInstance": () => Promise<MDCNotchedOutline>;
909915
/**
910916
* Styles the label in an outlined style
911917
*/
@@ -3598,7 +3604,7 @@ declare namespace LocalJSX {
35983604
*/
35993605
"onValueChange"?: (event: InoInputCustomEvent<string>) => void;
36003606
/**
3601-
* Styles the input field as outlined element.
3607+
* Styles the input field as outlined element. This property is immutable which means that it should not be changed after its first initialization. Changing this property at runtime causes problems in combination with the floating label. You can read more about this issue [here](https://github.com/inovex/elements/issues/1216).
36023608
*/
36033609
"outline"?: boolean;
36043610
/**

packages/elements/src/components/ino-input/ino-input.tsx

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import classNames from 'classnames';
1818
import { generateUniqueId, hasSlotContent } from '../../util/component-utils';
1919
import { getPrecision } from '../../util/math-utils';
2020
import { InputType, UserInputInterceptor } from '../types';
21+
import { MDCNotchedOutline } from '@material/notched-outline';
2122

2223
/**
2324
* An input component with styles. It functions as a wrapper around the material [textfield](https://github.com/material-components/material-components-web/tree/master/packages/mdc-textfield) component.
@@ -36,6 +37,7 @@ export class Input implements ComponentInterface {
3637
@Element() el!: HTMLInoInputElement;
3738

3839
private nativeInputEl?: HTMLInputElement;
40+
private inoLabelElement?: HTMLInoLabelElement;
3941
private cursorPosition = 0;
4042

4143
/**
@@ -54,12 +56,12 @@ export class Input implements ComponentInterface {
5456
private mdcTextfield: MDCTextField;
5557

5658
/**
57-
* An internal instance of an textfield helper text instance (if neccessary).
59+
* An internal instance of a textfield helper text instance (if necessary).
5860
*/
5961
private mdcHelperText: MDCTextFieldHelperText;
6062

6163
/**
62-
* An internal instance of an textfield icon instance (if neccessary).
64+
* An internal instance of a textfield icon instance (if necessary).
6365
*/
6466
private mdcTextfieldIcon: MDCTextFieldIcon;
6567

@@ -163,9 +165,21 @@ export class Input implements ComponentInterface {
163165

164166
/**
165167
* Styles the input field as outlined element.
168+
*
169+
* This property is immutable which means that it should not be changed after its first initialization.
170+
* Changing this property at runtime causes problems in combination with the floating label.
171+
* You can read more about this issue [here](https://github.com/inovex/elements/issues/1216).
166172
*/
167173
@Prop() outline?: boolean;
168174

175+
@Watch('outline')
176+
handleOutlineChange(oldVal: boolean, newVal: boolean) {
177+
if (oldVal !== newVal)
178+
console.warn(
179+
`Changing the 'outline' property at runtime is not recommended. Read more about it here: https://github.com/inovex/elements/issues/1216`,
180+
);
181+
}
182+
169183
/**
170184
* The validation pattern of this element.
171185
*/
@@ -260,20 +274,15 @@ export class Input implements ComponentInterface {
260274
// Lifecycle methods
261275
// ----
262276

263-
componentDidLoad() {
277+
async componentDidLoad() {
264278
this.mdcTextfield = new MDCTextField(
265279
this.el.querySelector('.mdc-text-field'),
266280
);
267281

268-
if (this.type === 'email') {
269-
this.mdcTextfield.useNativeValidation = false;
270-
}
271-
272282
if (this.helper) {
273-
const helperTextEl = document.querySelector(
274-
'.mdc-text-field-helper-text',
283+
this.mdcHelperText = new MDCTextFieldHelperText(
284+
this.el.querySelector('.mdc-text-field-helper-text'),
275285
);
276-
this.mdcHelperText = new MDCTextFieldHelperText(helperTextEl);
277286
}
278287

279288
if (
@@ -284,6 +293,23 @@ export class Input implements ComponentInterface {
284293
this.el.querySelector('.mdc-text-field__icon'),
285294
);
286295
}
296+
297+
const mdcNotchedOutline =
298+
await this.inoLabelElement.getMdcNotchedOutlineInstance();
299+
this.mdcTextfield.initialize(
300+
undefined,
301+
undefined,
302+
(el) => this.mdcHelperText ?? new MDCTextFieldHelperText(el),
303+
undefined,
304+
(el) => this.mdcTextfieldIcon ?? new MDCTextFieldIcon(el),
305+
undefined,
306+
(el) => mdcNotchedOutline ?? new MDCNotchedOutline(el),
307+
);
308+
309+
if (this.type === 'email') {
310+
this.mdcTextfield.useNativeValidation = false;
311+
}
312+
287313
this.textfieldValue = this.value || '';
288314

289315
if (this.autoFocus) {
@@ -306,8 +332,6 @@ export class Input implements ComponentInterface {
306332

307333
disconnectedCallback() {
308334
this.mdcTextfield?.destroy();
309-
this.mdcHelperText?.destroy();
310-
this.mdcTextfieldIcon?.destroy();
311335
}
312336

313337
// ----
@@ -492,6 +516,7 @@ export class Input implements ComponentInterface {
492516
<Host>
493517
<span class={classTextfield}>
494518
<ino-label
519+
ref={(el) => (this.inoLabelElement = el)}
495520
for={this.inputID}
496521
outline={this.outline}
497522
text={this.label}

0 commit comments

Comments
 (0)