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

fix(core/input-group): add padding left for error image #838

Merged
merged 4 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion packages/core/scss/components/form/_input.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
padding: 0.25rem 0.5rem;
background-color: var(--theme-input--background);
color: var(--theme-input--color);

text-overflow: ellipsis;
border: var(--theme-input--border-thickness, 1px) solid
var(--theme-input--border-color);
border-radius: var(--theme-input--border-radius);
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/components/input-group/input-group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ export class InputGroup {
this.inputElement.form?.noValidate === false) &&
!this.inputElement.validity.valid
) {
this.inputElement.style.backgroundPositionX = `${this.inputPaddingLeft}px`;
const left = this.inputPaddingLeft !== 0 ? this.inputPaddingLeft : 8;
this.inputElement.style.backgroundPositionX = `${left}px`;
this.inputPaddingLeft += 32;
}
});
Expand Down
61 changes: 61 additions & 0 deletions packages/core/src/components/input-group/tests/input-group.ct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,64 @@ test('update padding end', async ({ mount, page }) => {
await expect(input).toHaveCSS('padding-left', '55px');
await expect(input).toHaveCSS('padding-right', '65px');
});

test('validation padding', async ({ mount, page }) => {
await mount(`
<form class="needs-validation" noValidation>
<ix-input-group>
<input type="text" required />
</ix-input-group>

<ix-button type="submit">Submit</ix-button>
</form>
`);

const form = page.locator('form');
await form.evaluate((form) =>
form.addEventListener('submit', (e) => {
e.preventDefault();
form.classList.add('was-validated');
})
);

const group = page.locator('ix-input-group');
await expect(group).toHaveClass(/hydrated/);

const input = group.locator('input');
const button = page.locator('ix-button');

await button.click();

await expect(input).toHaveCSS('background-position-x', '8px');
});

test('validation padding with input-start slot', async ({ mount, page }) => {
await mount(`
<form class="needs-validation" noValidation>
<ix-input-group>
<ix-icon name="eye" size="12" slot="input-start"></ix-icon>
<input type="text" required />
</ix-input-group>

<ix-button type="submit">Submit</ix-button>
</form>
`);

const form = page.locator('form');
await form.evaluate((form) =>
form.addEventListener('submit', (e) => {
e.preventDefault();
form.classList.add('was-validated');
})
);

const group = page.locator('ix-input-group');
await expect(group).toHaveClass(/hydrated/);

const input = group.locator('input');
const button = page.locator('ix-button');

await button.click();

await expect(input).toHaveCSS('background-position-x', '27px');
});