-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(text-field): expose focusElement() method (#908)
* feat(text-field): add focus method * feat(text-field): add focus method * feat(text-field): revert banner readme to previous commit * feat(text-field): revert icon readme to previous commit * feat(text-field): revert table header cell readme to previous commit * fix: call native focus method instead of dispatch event * feat(text-field): rename focusTextField to focusElement * ci: saving screenshots of failing tests (#964) * test: saving screenshots of failing tests * test: corrected output directory * test: fix output directory path * test: using artifacts upload v4 * test: reverting to older ubuntu version * test: lowering artifacts retention days * feat(text-field): add focus method * feat(text-field): add focus method * feat(text-field): revert banner readme to previous commit * feat(text-field): revert icon readme to previous commit * feat(text-field): revert table header cell readme to previous commit * fix: call native focus method instead of dispatch event * feat(text-field): rename focusTextField to focusElement --------- Co-authored-by: Johan Lundgren <[email protected]> Co-authored-by: Charles Krook <[email protected]>
- Loading branch information
1 parent
febb7a5
commit 1298756
Showing
6 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
packages/core/src/components/text-field/test/focus/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!DOCTYPE html> | ||
<html lang="en" dir="ltr"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>Text Field - Focus</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0" /> | ||
<link rel="stylesheet" href="../../../../../dist/tegel/tegel.css" /> | ||
<script type="module"> | ||
import { defineCustomElements } from '../../../../../loader/index.es2017.js'; | ||
defineCustomElements(); | ||
</script> | ||
</head> | ||
|
||
<body> | ||
<tds-text-field | ||
type="text" | ||
size="lg" | ||
state="default" | ||
label="Label" | ||
label-position="no label" | ||
placeholder="Placeholder" | ||
></tds-text-field> | ||
</body> | ||
</html> |
53 changes: 53 additions & 0 deletions
53
packages/core/src/components/text-field/test/focus/text-field.e2e.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { expect } from '@playwright/test'; | ||
import { test } from 'stencil-playwright'; | ||
|
||
// Defined once for reuse | ||
const componentTestPath = 'src/components/text-field/test/focus/index.html'; | ||
const textFieldSelector = 'tds-text-field'; | ||
|
||
test.describe.parallel('TdsTextField - Focus', () => { | ||
test.beforeEach(async ({ page }) => { | ||
// Navigate to the component test page before each test | ||
await page.goto(componentTestPath); | ||
}); | ||
|
||
test('renders as expected when focused programmatically', async ({ page }) => { | ||
const textField = page.locator(textFieldSelector); | ||
|
||
// Ensure that the component is rendered and interactable | ||
await expect(textField).toBeVisible(); | ||
|
||
// Trigger focus programmatically | ||
await textField.evaluate((element: any) => element.focusElement()); | ||
|
||
// Wait for any visual changes due to the focus action to take effect | ||
await page.waitForTimeout(100); | ||
|
||
// Capture and compare the screenshot after the focus event has been triggered | ||
await expect(page).toHaveScreenshot({ maxDiffPixels: 0 }); | ||
}); | ||
|
||
test('allows text to be entered after focus', async ({ page }) => { | ||
const textField = page.locator(textFieldSelector); | ||
const inputField = textField.locator('input'); | ||
|
||
// Ensure the component is visible and ready | ||
await expect(textField).toBeVisible(); | ||
|
||
// Trigger focus programmatically | ||
await textField.evaluate((element: any) => element.focusElement()); | ||
|
||
// Wait for any visual changes due to the focus action to take effect | ||
await page.waitForTimeout(100); | ||
|
||
// Type some text into the input field | ||
const textToInput = 'Test text'; | ||
await inputField.fill(textToInput); | ||
|
||
// Verify the input field has the correct value after typing | ||
await expect(inputField).toHaveValue(textToInput); | ||
|
||
// Take a screenshot of the rendered text | ||
await expect(page).toHaveScreenshot({ maxDiffPixels: 0 }); | ||
}); | ||
}); |
Binary file added
BIN
+5.16 KB
...napshots/TdsTextField---Focus-allows-text-to-be-entered-after-focus-1-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.41 KB
...TextField---Focus-renders-as-expected-when-focused-programmatically-1-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters