feat(input): add the readonly styles for the ionic theme (#29483)

Issue number: internal

---------

## What is the current behavior?
There are no custom styles when readonly is added to an input.

## What is the new behavior?
- Applies an `input-readonly` class when the `readonly` property is
`true`
- Styles the class in the `ionic` theme to match the design requirements
for readonly inputs
- Adds screenshot tests for the readonly style for an unset `fill` and
`"outline"` fill

## Does this introduce a breaking change?

- [ ] Yes
- [x] No
This commit is contained in:
Brandy Carney
2024-05-10 11:38:18 -04:00
committed by GitHub
parent 8515c4efff
commit 09935fd07b
10 changed files with 87 additions and 7 deletions

View File

@ -7,6 +7,8 @@
// --------------------------------------------------
:host {
// TODO(ROU-5477): use design token here when it is added
--color: #121212;
--border-width: #{$ionic-border-size-small};
--border-color: #{$ionic-color-neutral-300};
--highlight-color-valid: #{$ionic-color-success-400};
@ -178,6 +180,13 @@
opacity: 0.6;
}
// Input - Readonly
// ----------------------------------------------------------------
:host(.input-readonly) {
--background: #{tokens.$ionic-color-neutral-10};
}
// Input Highlight
// ----------------------------------------------------------------

View File

@ -808,6 +808,7 @@ export class Input implements ComponentInterface {
'in-item': inItem,
'in-item-color': hostContext('ion-item.ion-color', this.el),
'input-disabled': disabled,
'input-readonly': readonly,
})}
>
{/**

View File

@ -50,7 +50,28 @@
<div class="grid-item">
<h2>No Fill</h2>
<ion-input label="Email" value="hi@ionic.io" readonly="true"></ion-input>
<ion-input
label="Email"
value="hi@ionic.io"
helper-text="Enter an email"
counter="true"
maxlength="20"
readonly="true"
></ion-input>
</div>
<div class="grid-item">
<h2>Outline</h2>
<ion-input
fill="outline"
label="Email"
value="hi@ionic.io"
helper-text="Enter an email"
counter="true"
maxlength="20"
readonly="true"
></ion-input>
</div>
</div>

View File

@ -175,5 +175,54 @@ configs({ modes: ['ionic-md'], directions: ['ltr'] }).forEach(({ title, screensh
await expect(container).toHaveScreenshot(screenshot(`input-focused`));
});
});
test.describe(title('readonly'), () => {
test.describe(title('no fill'), () => {
test('should render readonly input correctly', async ({ page }) => {
await page.setContent(
`
<div class="container">
<ion-input
label="Email"
value="hi@ionic.io"
helper-text="Enter an email"
counter="true"
maxlength="20"
readonly="true"
></ion-input>
</div>
`,
config
);
const container = page.locator('.container');
await expect(container).toHaveScreenshot(screenshot(`input-readonly-no-fill`));
});
});
test.describe(title('outline'), () => {
test('should render readonly input correctly', async ({ page }) => {
await page.setContent(
`
<div class="container">
<ion-input
fill="outline"
label="Email"
value="hi@ionic.io"
helper-text="Enter an email"
counter="true"
maxlength="20"
readonly="true"
></ion-input>
</div>
`,
config
);
const container = page.locator('.container');
await expect(container).toHaveScreenshot(screenshot(`input-readonly-outline`));
});
});
});
});
});