Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(input): add the large size for the ionic theme #29249

Merged
merged 6 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ ion-input,prop,placeholder,string | undefined,undefined,false,false
ion-input,prop,readonly,boolean,false,false,true
ion-input,prop,required,boolean,false,false,false
ion-input,prop,shape,"round" | undefined,undefined,false,false
ion-input,prop,size,"large" | undefined,undefined,false,false
ion-input,prop,spellcheck,boolean,false,false,false
ion-input,prop,step,string | undefined,undefined,false,false
ion-input,prop,theme,"ios" | "md" | "ionic",undefined,false,false
Expand Down
8 changes: 8 additions & 0 deletions core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,10 @@ export namespace Components {
* The shape of the input. If "round" it will have an increased border radius.
*/
"shape"?: 'round';
/**
* The size of the input. If "large", it will have an increased height. By default the size is unset. This property only applies to the `"ionic"` theme.
*/
"size"?: 'large';
/**
* If `true`, the element will have its spelling and grammar checked.
*/
Expand Down Expand Up @@ -6694,6 +6698,10 @@ declare namespace LocalJSX {
* The shape of the input. If "round" it will have an increased border radius.
*/
"shape"?: 'round';
/**
* The size of the input. If "large", it will have an increased height. By default the size is unset. This property only applies to the `"ionic"` theme.
*/
"size"?: 'large';
/**
* If `true`, the element will have its spelling and grammar checked.
*/
Expand Down
9 changes: 9 additions & 0 deletions core/src/components/input/input.ionic.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@

// Ionic Input
// --------------------------------------------------



// Ionic Input Sizes
// --------------------------------------------------

:host(.input-size-large) {
min-height: 48px;
}
19 changes: 19 additions & 0 deletions core/src/components/input/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { NotchController } from '@utils/forms';
import { createNotchController } from '@utils/forms';
import type { Attributes } from '@utils/helpers';
import { inheritAriaAttributes, debounceEvent, inheritAttributes, componentOnReady } from '@utils/helpers';
import { printIonWarning } from '@utils/logging';
import { createSlotMutationController } from '@utils/slot-mutation-controller';
import type { SlotMutationController } from '@utils/slot-mutation-controller';
import { createColorClasses, hostContext } from '@utils/theme';
Expand Down Expand Up @@ -251,6 +252,12 @@ export class Input implements ComponentInterface {
*/
@Prop() step?: string;

/**
* The size of the input. If "large", it will have an increased height. By default the
* size is unset. This property only applies to the `"ionic"` theme.
*/
@Prop() size?: 'large';

/**
* The type of control to display. The default type is text.
*/
Expand Down Expand Up @@ -464,6 +471,16 @@ export class Input implements ComponentInterface {
return typeof this.value === 'number' ? this.value.toString() : (this.value || '').toString();
}

private getSize() {
const theme = getIonTheme(this);
const { size } = this;
if (theme !== 'ionic' && size === 'large') {
printIonWarning(`The "${size}" size is not supported in the ${theme} theme.`);
return undefined;
}
return size;
}

private onInput = (ev: InputEvent | Event) => {
const input = ev.target as HTMLInputElement | null;
if (input) {
Expand Down Expand Up @@ -686,6 +703,7 @@ export class Input implements ComponentInterface {
const { disabled, fill, readonly, shape, inputId, labelPlacement, el, hasFocus } = this;
const theme = getIonTheme(this);
const value = this.getValue();
const size = this.getSize();
const inItem = hostContext('ion-item', this.el);
const shouldRenderHighlight = theme === 'md' && fill !== 'outline' && !inItem;

Expand Down Expand Up @@ -721,6 +739,7 @@ export class Input implements ComponentInterface {
'label-floating': labelShouldFloat,
[`input-fill-${fill}`]: fill !== undefined,
[`input-shape-${shape}`]: shape !== undefined,
[`input-size-${size}`]: size !== undefined,
[`input-label-placement-${labelPlacement}`]: true,
'in-item': inItem,
'in-item-color': hostContext('ion-item.ion-color', this.el),
Expand Down
74 changes: 74 additions & 0 deletions core/src/components/input/test/size/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8" />
<title>Input - Size</title>
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
/>
<link href="../../../../../css/ionic.bundle.css" rel="stylesheet" />
<link href="../../../../../scripts/testing/styles.css" rel="stylesheet" />
<script src="../../../../../scripts/testing/scripts.js"></script>
<script nomodule src="../../../../../dist/ionic/ionic.js"></script>
<script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script>
<style>
.grid {
display: grid;
grid-template-columns: repeat(2, minmax(250px, 1fr));
grid-row-gap: 20px;
grid-column-gap: 20px;
}

h2 {
font-size: 12px;
font-weight: normal;

color: #6f7378;

margin-top: 10px;
}

@media screen and (max-width: 800px) {
.grid {
grid-template-columns: 1fr;
padding: 0;
}
}
</style>
</head>

<body>
<ion-app>
<ion-header>
<ion-toolbar>
<ion-title>Input - Size</ion-title>
</ion-toolbar>
</ion-header>

<ion-content id="content" class="ion-padding">
<div class="grid">
<div class="grid-item">
<h2>No Fill: No Size</h2>
<ion-input label="Email"></ion-input>
</div>

<div class="grid-item">
<h2>Outline: No Size</h2>
<ion-input fill="outline" label="Email"></ion-input>
</div>

<div class="grid-item">
<h2>No Fill: Large Size</h2>
<ion-input size="large" label="Email"></ion-input>
</div>

<div class="grid-item">
<h2>Outline: Large Size</h2>
<ion-input size="large" fill="outline" label="Email"></ion-input>
</div>
</div>
</ion-content>
</ion-app>
</body>
</html>
78 changes: 78 additions & 0 deletions core/src/components/input/test/size/input.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { expect } from '@playwright/test';
import { configs, test } from '@utils/test/playwright';

/**
* Size is only available in the Ionic theme
*/
configs({ modes: ['ionic-md'], directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
test.describe(title('input: size'), () => {
test.describe('input: size large', () => {
test('should not have visual regressions', async ({ page }) => {
await page.setContent(
`
<ion-input
size="large"
label="Email"
value="hi@ionic.io"
></ion-input>
`,
config
);

const input = page.locator('ion-input');
await expect(input).toHaveScreenshot(screenshot(`input-size-large`));
});
test('should render correctly with floating label', async ({ page }) => {
await page.setContent(
`
<ion-input
size="large"
label="Email"
label-placement="floating"
value="hi@ionic.io"
></ion-input>
`,
config
);

const input = page.locator('ion-input');
await expect(input).toHaveScreenshot(screenshot(`input-size-large-label-floating`));
});
test('should not have visual regressions with fill outline', async ({ page }) => {
await page.setContent(
`
<ion-input
fill="outline"
size="large"
label="Email"
label-placement="floating"
value="hi@ionic.io"
></ion-input>
`,
config
);

const input = page.locator('ion-input');
await expect(input).toHaveScreenshot(screenshot(`input-size-large-outline`));
});
test('should not have visual regressions with fill outline and round shape', async ({ page }) => {
await page.setContent(
`
<ion-input
fill="outline"
shape="round"
size="large"
label="Email"
label-placement="floating"
value="hi@ionic.io"
></ion-input>
`,
config
);

const input = page.locator('ion-input');
await expect(input).toHaveScreenshot(screenshot(`input-size-large-outline-round`));
});
});
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions packages/angular/src/directives/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -957,15 +957,15 @@ export declare interface IonInfiniteScrollContent extends Components.IonInfinite


@ProxyCmp({
inputs: ['autocapitalize', 'autocomplete', 'autocorrect', 'autofocus', 'clearInput', 'clearOnEdit', 'color', 'counter', 'counterFormatter', 'debounce', 'disabled', 'enterkeyhint', 'errorText', 'fill', 'helperText', 'inputmode', 'label', 'labelPlacement', 'max', 'maxlength', 'min', 'minlength', 'mode', 'multiple', 'name', 'pattern', 'placeholder', 'readonly', 'required', 'shape', 'spellcheck', 'step', 'theme', 'type', 'value'],
inputs: ['autocapitalize', 'autocomplete', 'autocorrect', 'autofocus', 'clearInput', 'clearOnEdit', 'color', 'counter', 'counterFormatter', 'debounce', 'disabled', 'enterkeyhint', 'errorText', 'fill', 'helperText', 'inputmode', 'label', 'labelPlacement', 'max', 'maxlength', 'min', 'minlength', 'mode', 'multiple', 'name', 'pattern', 'placeholder', 'readonly', 'required', 'shape', 'size', 'spellcheck', 'step', 'theme', 'type', 'value'],
methods: ['setFocus', 'getInputElement']
})
@Component({
selector: 'ion-input',
changeDetection: ChangeDetectionStrategy.OnPush,
template: '<ng-content></ng-content>',
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
inputs: ['autocapitalize', 'autocomplete', 'autocorrect', 'autofocus', 'clearInput', 'clearOnEdit', 'color', 'counter', 'counterFormatter', 'debounce', 'disabled', 'enterkeyhint', 'errorText', 'fill', 'helperText', 'inputmode', 'label', 'labelPlacement', 'max', 'maxlength', 'min', 'minlength', 'mode', 'multiple', 'name', 'pattern', 'placeholder', 'readonly', 'required', 'shape', 'spellcheck', 'step', 'theme', 'type', 'value'],
inputs: ['autocapitalize', 'autocomplete', 'autocorrect', 'autofocus', 'clearInput', 'clearOnEdit', 'color', 'counter', 'counterFormatter', 'debounce', 'disabled', 'enterkeyhint', 'errorText', 'fill', 'helperText', 'inputmode', 'label', 'labelPlacement', 'max', 'maxlength', 'min', 'minlength', 'mode', 'multiple', 'name', 'pattern', 'placeholder', 'readonly', 'required', 'shape', 'size', 'spellcheck', 'step', 'theme', 'type', 'value'],
})
export class IonInput {
protected el: HTMLElement;
Expand Down
1 change: 1 addition & 0 deletions packages/vue/src/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ export const IonInput = /*@__PURE__*/ defineContainer<JSX.IonInput, JSX.IonInput
'shape',
'spellcheck',
'step',
'size',
'type',
'value',
'ionInput',
Expand Down
Loading