@politiet/sheriff-web-components 1.3.2 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -33,23 +33,18 @@ test.describe('textarea-component', () => {
33
33
  await expect(readonly).toHaveAttribute('readonly', '');
34
34
  });
35
35
  test('character counter visibility', async ({ page }) => {
36
- // Character counter should be visible for textareas with maxlength
37
- const withMaxlength = page.locator('#with-maxlength');
38
- const withMaxlengthCounter = withMaxlength.locator('.sds-textarea__character-counter');
39
- await expect(withMaxlengthCounter).toBeVisible();
40
- // Character counter should not be visible for textareas without maxlength
41
- const withoutMaxlength = page.locator('#without-maxlength');
42
- const withoutMaxlengthCounter = withoutMaxlength.locator('.sds-textarea__character-counter');
36
+ // Character counter should be visible for textareas with counter
37
+ const withCounter = page.locator('#with-counter');
38
+ const withCounterText = withCounter.locator('.sds-textarea__character-counter');
39
+ await expect(withCounterText).toBeVisible();
40
+ // Character counter should not be visible for textareas without counter
41
+ const withoutCounter = page.locator('#without-maxlength');
42
+ const withoutMaxlengthCounter = withoutCounter.locator('.sds-textarea__character-counter');
43
43
  await expect(withoutMaxlengthCounter).not.toBeVisible();
44
- // Character counter should be visible for textarea with initial value
45
- const withValue = page.locator('#with-value');
46
- const withValueCounter = withValue.locator('.sds-textarea__character-counter');
47
- await expect(withValueCounter).toBeVisible();
48
- await expect(withValueCounter).toHaveText('Du har 8 tegn igjen');
49
44
  });
50
45
  test('character counter updates on input', async ({ page }) => {
51
- const textarea = page.locator('#with-maxlength');
52
- const counter = page.locator('#with-maxlength').locator('.sds-textarea__character-counter');
46
+ const textarea = page.locator('#with-counter');
47
+ const counter = page.locator('#with-counter').locator('.sds-textarea__character-counter');
53
48
  // Initial state
54
49
  await expect(counter).toHaveText('Du har 10 tegn igjen');
55
50
  // Type some text
@@ -57,7 +52,7 @@ test.describe('textarea-component', () => {
57
52
  await expect(counter).toHaveText('Du har 5 tegn igjen');
58
53
  // Type more text
59
54
  await textarea.pressSequentially('Hello World');
60
- await expect(counter).toHaveText('Du har 0 tegn igjen');
55
+ await expect(counter).toHaveText('Du har 6 tegn for mye');
61
56
  });
62
57
  test('form-submission', async ({ page }) => {
63
58
  const getFormData = await onFormSubmitCallback(page, 'textarea-form');
@@ -76,14 +71,14 @@ test.describe('textarea-component', () => {
76
71
  // Change values
77
72
  await page.locator('#with-maxlength').pressSequentially('Changed text');
78
73
  await page.locator('#with-value').pressSequentially('New value');
74
+ await page.locator('#with-counter').pressSequentially('Some letters');
79
75
  // Reset the form
80
76
  await page.locator('#reset-button').click();
81
77
  // Check that values are reset
82
78
  await expect(page.locator('#with-maxlength')).toHaveValue('');
83
79
  await expect(page.locator('#with-value')).toHaveValue('Initial text');
84
80
  // Check that character counters are reset
85
- await expect(page.locator('#with-maxlength').locator('.sds-textarea__character-counter')).toHaveText('Du har 10 tegn igjen');
86
- await expect(page.locator('#with-value').locator('.sds-textarea__character-counter')).toHaveText('Du har 8 tegn igjen');
81
+ await expect(page.locator('#with-counter').locator('.sds-textarea__character-counter')).toHaveText('Du har 10 tegn igjen');
87
82
  });
88
83
  test('focus', async ({ page }) => {
89
84
  for (const id of textareaIds) {
@@ -167,5 +162,17 @@ test.describe('textarea-component', () => {
167
162
  expect(shadowDomTextarea).toBe(expected);
168
163
  }
169
164
  });
165
+ test('can be combined with external control of value attribute', async ({ page }) => {
166
+ const textAreaInsideShadowDOM = page.getByRole('textbox', { name: 'Text area in React' });
167
+ await expect(textAreaInsideShadowDOM).toHaveValue('Initial text');
168
+ // First clear and then type in the text area
169
+ await textAreaInsideShadowDOM.clear();
170
+ await textAreaInsideShadowDOM.fill('Something typed into the form');
171
+ await expect(textAreaInsideShadowDOM).toHaveValue('Something typed into the form');
172
+ // Then click the button to change the text to "Text set in React"
173
+ const reactButton = page.locator('#react-button');
174
+ await reactButton.click();
175
+ await expect(textAreaInsideShadowDOM).toHaveValue('Text set with React');
176
+ });
170
177
  });
171
178
  //# sourceMappingURL=sds-textarea.sp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,IAAI,EAAE,EAAE,CAAC,CAAC;YAEpC,+BAA+B;YAC/B,MAAM,MAAM,CAAC,IAAI,CAAC,CAAC,eAAe,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;YAE7D,oCAAoC;YACpC,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAe,EAAE,EAAE;gBACjE,MAAM,QAAQ,GAAG,EAAE,CAAC,UAAU,EAAE,aAAa,CAAC,UAAU,CAA+B,CAAC;gBACxF,OAAO,QAAQ,EAAE,YAAY,IAAI,IAAI,CAAC;YACvC,CAAC,CAAC,CAAC;YACH,MAAM,CAAC,iBAAiB,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC1C,CAAC;IACF,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import { test } from '@playwright/test';\nimport { onFormSubmitCallback } from '../playwright-util/form';\nimport { expect } from '../playwright-util/custom-matchers';\n\nconst pageUrl = 'iframe.html?viewMode=docs&id=test-textarea--docs';\nconst textareaIds = [\n\t'with-maxlength',\n\t'with-min-max',\n\t'without-maxlength',\n\t'with-error',\n\t'with-value',\n\t'readonly',\n\t'required',\n\t'autocomplete-off',\n\t'autocomplete-on',\n];\n\ntest.describe('textarea-component', () => {\n\ttest.beforeEach(async ({ page }) => {\n\t\tawait page.goto(pageUrl);\n\t});\n\n\ttest('visibility', async ({ page }) => {\n\t\tfor (const id of textareaIds) {\n\t\t\tawait expect(page.locator(`#${id}`)).toBeVisible();\n\t\t}\n\t});\n\n\ttest('initial states', async ({ page }) => {\n\t\t// Check that textarea with value has the correct initial value\n\t\tconst withValue = page.locator('#with-value');\n\t\tawait expect(withValue).toHaveValue('Initial text');\n\n\t\t// Check that disabled textarea is disabled\n\t\tconst disabled = page.locator('#disabled');\n\t\tawait expect(disabled).toHaveAttribute('disabled', '');\n\n\t\tconst readonly = page.locator('#readonly');\n\t\tawait expect(readonly).toHaveAttribute('readonly', '');\n\t});\n\n\ttest('character counter visibility', async ({ page }) => {\n\t\t// Character counter should be visible for textareas with maxlength\n\t\tconst withMaxlength = page.locator('#with-maxlength');\n\t\tconst withMaxlengthCounter = withMaxlength.locator('.sds-textarea__character-counter');\n\t\tawait expect(withMaxlengthCounter).toBeVisible();\n\n\t\t// Character counter should not be visible for textareas without maxlength\n\t\tconst withoutMaxlength = page.locator('#without-maxlength');\n\t\tconst withoutMaxlengthCounter = withoutMaxlength.locator('.sds-textarea__character-counter');\n\t\tawait expect(withoutMaxlengthCounter).not.toBeVisible();\n\n\t\t// Character counter should be visible for textarea with initial value\n\t\tconst withValue = page.locator('#with-value');\n\t\tconst withValueCounter = withValue.locator('.sds-textarea__character-counter');\n\t\tawait expect(withValueCounter).toBeVisible();\n\t\tawait expect(withValueCounter).toHaveText('Du har 8 tegn igjen');\n\t});\n\n\ttest('character counter updates on input', async ({ page }) => {\n\t\tconst textarea = page.locator('#with-maxlength');\n\t\tconst counter = page.locator('#with-maxlength').locator('.sds-textarea__character-counter');\n\n\t\t// Initial state\n\t\tawait expect(counter).toHaveText('Du har 10 tegn igjen');\n\n\t\t// Type some text\n\t\tawait textarea.pressSequentially('Hello');\n\t\tawait expect(counter).toHaveText('Du har 5 tegn igjen');\n\n\t\t// Type more text\n\t\tawait textarea.pressSequentially('Hello World');\n\t\tawait expect(counter).toHaveText('Du har 0 tegn igjen');\n\t});\n\n\ttest('form-submission', async ({ page }) => {\n\t\tconst getFormData = await onFormSubmitCallback(page, 'textarea-form');\n\n\t\t// Fill in some textareas\n\t\tawait page.locator('#with-maxlength').pressSequentially('Test');\n\t\tawait page.locator('#with-min-max').pressSequentially('Test input');\n\n\t\tawait page.locator('#submit-button').click();\n\n\t\tawait expect.poll(async () => (await getFormData()) !== null, 'Form data not received').toBeTruthy();\n\t\tconst formData = await getFormData();\n\n\t\texpect(formData).toMatchObject({\n\t\t\t'with-maxlength': 'Test',\n\t\t\t'with-min-max': 'Test input',\n\t\t});\n\t});\n\n\ttest('form-reset', async ({ page }) => {\n\t\t// Change values\n\t\tawait page.locator('#with-maxlength').pressSequentially('Changed text');\n\t\tawait page.locator('#with-value').pressSequentially('New value');\n\n\t\t// Reset the form\n\t\tawait page.locator('#reset-button').click();\n\n\t\t// Check that values are reset\n\t\tawait expect(page.locator('#with-maxlength')).toHaveValue('');\n\t\tawait expect(page.locator('#with-value')).toHaveValue('Initial text');\n\n\t\t// Check that character counters are reset\n\t\tawait expect(page.locator('#with-maxlength').locator('.sds-textarea__character-counter')).toHaveText(\n\t\t\t'Du har 10 tegn igjen'\n\t\t);\n\t\tawait expect(page.locator('#with-value').locator('.sds-textarea__character-counter')).toHaveText(\n\t\t\t'Du har 8 tegn igjen'\n\t\t);\n\t});\n\n\ttest('focus', async ({ page }) => {\n\t\tfor (const id of textareaIds) {\n\t\t\tif (id === 'disabled') continue; // Skip disabled textarea\n\n\t\t\t// Prepare for focus test by adding a parent div for consistent screenshots\n\t\t\tawait page.evaluate((id) => {\n\t\t\t\tconst element = document.getElementById(id);\n\t\t\t\tif (element) {\n\t\t\t\t\tconst parentDiv = document.createElement('div');\n\t\t\t\t\tparentDiv.style.padding = '10px';\n\t\t\t\t\tparentDiv.style.backgroundColor = 'white';\n\t\t\t\t\telement.parentNode?.insertBefore(parentDiv, element);\n\t\t\t\t\tparentDiv.appendChild(element);\n\t\t\t\t}\n\t\t\t}, id);\n\n\t\t\t// Focus the textarea\n\t\t\tawait page.locator(`#${id}`).focus();\n\n\t\t\t// Verify focus state\n\t\t\tconst isFocused = await page.evaluate((id) => {\n\t\t\t\tconst element = document.getElementById(id);\n\t\t\t\treturn element === document.activeElement;\n\t\t\t}, id);\n\n\t\t\texpect(isFocused).toBeTruthy();\n\t\t}\n\t});\n\n\ttest('minlength', async ({ page }) => {\n\t\tconst textarea = page.locator('#with-min-max');\n\n\t\t// Text shorter than minlength (5) → invalid\n\t\tawait textarea.pressSequentially('abc');\n\t\tconst isValidShort = await textarea.evaluate((el: HTMLTextAreaElement) => el.checkValidity());\n\t\texpect(isValidShort).toBe(false);\n\n\t\t// Text exactly at minlength (5) → valid\n\t\tawait page.goto(pageUrl);\n\t\tawait textarea.pressSequentially('abcde');\n\t\tconst isValidExact = await textarea.evaluate((el: HTMLTextAreaElement) => el.checkValidity());\n\t\texpect(isValidExact).toBe(true);\n\n\t\t// Text longer than minlength (5) → valid\n\t\tawait page.goto(pageUrl);\n\t\tawait textarea.pressSequentially('abcdefg');\n\t\tconst isValidLong = await textarea.evaluate((el: HTMLTextAreaElement) => el.checkValidity());\n\t\texpect(isValidLong).toBe(true);\n\t});\n\n\ttest('maxlength', async ({ page }) => {\n\t\tconst longStringToType = 'abcdefghijklmnop';\n\t\tconst textarea = page.locator('#with-maxlength');\n\n\t\t// Type in string longer than the 10 character maxlength\n\t\tawait textarea.pressSequentially(longStringToType);\n\t\tawait expect(textarea).toHaveValue(longStringToType.substring(0, 10));\n\t});\n\n\ttest('required', async ({ page }) => {\n\t\tconst textarea = page.locator('#required');\n\n\t\t// No value → invalid\n\t\tlet isValid = await textarea.evaluate((el: HTMLTextAreaElement) => el.checkValidity());\n\t\texpect(isValid).toBe(false);\n\n\t\t// Has value → valid\n\t\tawait page.goto(pageUrl);\n\t\tawait textarea.pressSequentially('abc');\n\t\tisValid = await textarea.evaluate((el: HTMLTextAreaElement) => el.checkValidity());\n\t\texpect(isValid).toBe(true);\n\t});\n\n\ttest('readonly', async ({ page }) => {\n\t\tconst textarea = page.locator('#readonly');\n\t\tawait textarea.pressSequentially('abc');\n\t\tawait expect(textarea).toHaveValue('Cannot be changed');\n\t});\n\n\ttest('autocomplete on/off', async ({ page }) => {\n\t\tconst textareas = [\n\t\t\t{ id: 'autocomplete-off', expected: 'off' },\n\t\t\t{ id: 'autocomplete-on', expected: 'on' },\n\t\t];\n\n\t\tfor (const { id, expected } of textareas) {\n\t\t\tconst host = page.locator(`#${id}`);\n\n\t\t\t// Check host element attribute\n\t\t\tawait expect(host).toHaveAttribute('autocomplete', expected);\n\n\t\t\t// Check shadow DOM textarea element\n\t\t\tconst shadowDomTextarea = await host.evaluate((el: HTMLElement) => {\n\t\t\t\tconst textarea = el.shadowRoot?.querySelector('textarea') as HTMLTextAreaElement | null;\n\t\t\t\treturn textarea?.autocomplete ?? null;\n\t\t\t});\n\t\t\texpect(shadowDomTextarea).toBe(expected);\n\t\t}\n\t});\n});\n"]}
1
+ {"version":3,"file":"sds-textarea.spec.js","sourceRoot":"","sources":["../../src/sds-textarea/sds-textarea.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AAE5D,MAAM,OAAO,GAAG,kDAAkD,CAAC;AACnE,MAAM,WAAW,GAAG;IACnB,gBAAgB;IAChB,cAAc;IACd,mBAAmB;IACnB,YAAY;IACZ,YAAY;IACZ,UAAU;IACV,UAAU;IACV,kBAAkB;IAClB,iBAAiB;CACjB,CAAC;AAEF,IAAI,CAAC,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IACxC,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE;QAClC,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC1B,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,YAAY,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE;QACrC,KAAK,MAAM,EAAE,IAAI,WAAW,EAAE,CAAC;YAC9B,MAAM,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;QACpD,CAAC;IACF,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,gBAAgB,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE;QACzC,+DAA+D;QAC/D,MAAM,S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M,iBAAiB,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAe,EAAE,EAAE;gBACjE,MAAM,QAAQ,GAAG,EAAE,CAAC,UAAU,EAAE,aAAa,CAAC,UAAU,CAA+B,CAAC;gBACxF,OAAO,QAAQ,EAAE,YAAY,IAAI,IAAI,CAAC;YACvC,CAAC,CAAC,CAAC;YACH,MAAM,CAAC,iBAAiB,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC1C,CAAC;IACF,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,0DAA0D,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE;QACnF,MAAM,uBAAuB,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,EAAE,IAAI,EAAE,oBAAoB,EAAE,CAAC,CAAC;QAC1F,MAAM,MAAM,CAAC,uBAAuB,CAAC,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;QAElE,6CAA6C;QAC7C,MAAM,uBAAuB,CAAC,KAAK,EAAE,CAAC;QACtC,MAAM,uBAAuB,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC;QACpE,MAAM,MAAM,CAAC,uBAAuB,CAAC,CAAC,WAAW,CAAC,+BAA+B,CAAC,CAAC;QAEnF,kEAAkE;QAClE,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;QAClD,MAAM,WAAW,CAAC,KAAK,EAAE,CAAC;QAE1B,MAAM,MAAM,CAAC,uBAAuB,CAAC,CAAC,WAAW,CAAC,qBAAqB,CAAC,CAAC;IAC1E,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import { test } from '@playwright/test';\nimport { onFormSubmitCallback } from '../playwright-util/form';\nimport { expect } from '../playwright-util/custom-matchers';\n\nconst pageUrl = 'iframe.html?viewMode=docs&id=test-textarea--docs';\nconst textareaIds = [\n\t'with-maxlength',\n\t'with-min-max',\n\t'without-maxlength',\n\t'with-error',\n\t'with-value',\n\t'readonly',\n\t'required',\n\t'autocomplete-off',\n\t'autocomplete-on',\n];\n\ntest.describe('textarea-component', () => {\n\ttest.beforeEach(async ({ page }) => {\n\t\tawait page.goto(pageUrl);\n\t});\n\n\ttest('visibility', async ({ page }) => {\n\t\tfor (const id of textareaIds) {\n\t\t\tawait expect(page.locator(`#${id}`)).toBeVisible();\n\t\t}\n\t});\n\n\ttest('initial states', async ({ page }) => {\n\t\t// Check that textarea with value has the correct initial value\n\t\tconst withValue = page.locator('#with-value');\n\t\tawait expect(withValue).toHaveValue('Initial text');\n\n\t\t// Check that disabled textarea is disabled\n\t\tconst disabled = page.locator('#disabled');\n\t\tawait expect(disabled).toHaveAttribute('disabled', '');\n\n\t\tconst readonly = page.locator('#readonly');\n\t\tawait expect(readonly).toHaveAttribute('readonly', '');\n\t});\n\n\ttest('character counter visibility', async ({ page }) => {\n\t\t// Character counter should be visible for textareas with counter\n\t\tconst withCounter = page.locator('#with-counter');\n\t\tconst withCounterText = withCounter.locator('.sds-textarea__character-counter');\n\t\tawait expect(withCounterText).toBeVisible();\n\n\t\t// Character counter should not be visible for textareas without counter\n\t\tconst withoutCounter = page.locator('#without-maxlength');\n\t\tconst withoutMaxlengthCounter = withoutCounter.locator('.sds-textarea__character-counter');\n\t\tawait expect(withoutMaxlengthCounter).not.toBeVisible();\n\t});\n\n\ttest('character counter updates on input', async ({ page }) => {\n\t\tconst textarea = page.locator('#with-counter');\n\t\tconst counter = page.locator('#with-counter').locator('.sds-textarea__character-counter');\n\n\t\t// Initial state\n\t\tawait expect(counter).toHaveText('Du har 10 tegn igjen');\n\n\t\t// Type some text\n\t\tawait textarea.pressSequentially('Hello');\n\t\tawait expect(counter).toHaveText('Du har 5 tegn igjen');\n\n\t\t// Type more text\n\t\tawait textarea.pressSequentially('Hello World');\n\t\tawait expect(counter).toHaveText('Du har 6 tegn for mye');\n\t});\n\n\ttest('form-submission', async ({ page }) => {\n\t\tconst getFormData = await onFormSubmitCallback(page, 'textarea-form');\n\n\t\t// Fill in some textareas\n\t\tawait page.locator('#with-maxlength').pressSequentially('Test');\n\t\tawait page.locator('#with-min-max').pressSequentially('Test input');\n\n\t\tawait page.locator('#submit-button').click();\n\n\t\tawait expect.poll(async () => (await getFormData()) !== null, 'Form data not received').toBeTruthy();\n\t\tconst formData = await getFormData();\n\n\t\texpect(formData).toMatchObject({\n\t\t\t'with-maxlength': 'Test',\n\t\t\t'with-min-max': 'Test input',\n\t\t});\n\t});\n\n\ttest('form-reset', async ({ page }) => {\n\t\t// Change values\n\t\tawait page.locator('#with-maxlength').pressSequentially('Changed text');\n\t\tawait page.locator('#with-value').pressSequentially('New value');\n\t\tawait page.locator('#with-counter').pressSequentially('Some letters');\n\n\t\t// Reset the form\n\t\tawait page.locator('#reset-button').click();\n\n\t\t// Check that values are reset\n\t\tawait expect(page.locator('#with-maxlength')).toHaveValue('');\n\t\tawait expect(page.locator('#with-value')).toHaveValue('Initial text');\n\n\t\t// Check that character counters are reset\n\t\tawait expect(page.locator('#with-counter').locator('.sds-textarea__character-counter')).toHaveText(\n\t\t\t'Du har 10 tegn igjen'\n\t\t);\n\t});\n\n\ttest('focus', async ({ page }) => {\n\t\tfor (const id of textareaIds) {\n\t\t\tif (id === 'disabled') continue; // Skip disabled textarea\n\n\t\t\t// Prepare for focus test by adding a parent div for consistent screenshots\n\t\t\tawait page.evaluate((id) => {\n\t\t\t\tconst element = document.getElementById(id);\n\t\t\t\tif (element) {\n\t\t\t\t\tconst parentDiv = document.createElement('div');\n\t\t\t\t\tparentDiv.style.padding = '10px';\n\t\t\t\t\tparentDiv.style.backgroundColor = 'white';\n\t\t\t\t\telement.parentNode?.insertBefore(parentDiv, element);\n\t\t\t\t\tparentDiv.appendChild(element);\n\t\t\t\t}\n\t\t\t}, id);\n\n\t\t\t// Focus the textarea\n\t\t\tawait page.locator(`#${id}`).focus();\n\n\t\t\t// Verify focus state\n\t\t\tconst isFocused = await page.evaluate((id) => {\n\t\t\t\tconst element = document.getElementById(id);\n\t\t\t\treturn element === document.activeElement;\n\t\t\t}, id);\n\n\t\t\texpect(isFocused).toBeTruthy();\n\t\t}\n\t});\n\n\ttest('minlength', async ({ page }) => {\n\t\tconst textarea = page.locator('#with-min-max');\n\n\t\t// Text shorter than minlength (5) → invalid\n\t\tawait textarea.pressSequentially('abc');\n\t\tconst isValidShort = await textarea.evaluate((el: HTMLTextAreaElement) => el.checkValidity());\n\t\texpect(isValidShort).toBe(false);\n\n\t\t// Text exactly at minlength (5) → valid\n\t\tawait page.goto(pageUrl);\n\t\tawait textarea.pressSequentially('abcde');\n\t\tconst isValidExact = await textarea.evaluate((el: HTMLTextAreaElement) => el.checkValidity());\n\t\texpect(isValidExact).toBe(true);\n\n\t\t// Text longer than minlength (5) → valid\n\t\tawait page.goto(pageUrl);\n\t\tawait textarea.pressSequentially('abcdefg');\n\t\tconst isValidLong = await textarea.evaluate((el: HTMLTextAreaElement) => el.checkValidity());\n\t\texpect(isValidLong).toBe(true);\n\t});\n\n\ttest('maxlength', async ({ page }) => {\n\t\tconst longStringToType = 'abcdefghijklmnop';\n\t\tconst textarea = page.locator('#with-maxlength');\n\n\t\t// Type in string longer than the 10 character maxlength\n\t\tawait textarea.pressSequentially(longStringToType);\n\t\tawait expect(textarea).toHaveValue(longStringToType.substring(0, 10));\n\t});\n\n\ttest('required', async ({ page }) => {\n\t\tconst textarea = page.locator('#required');\n\n\t\t// No value → invalid\n\t\tlet isValid = await textarea.evaluate((el: HTMLTextAreaElement) => el.checkValidity());\n\t\texpect(isValid).toBe(false);\n\n\t\t// Has value → valid\n\t\tawait page.goto(pageUrl);\n\t\tawait textarea.pressSequentially('abc');\n\t\tisValid = await textarea.evaluate((el: HTMLTextAreaElement) => el.checkValidity());\n\t\texpect(isValid).toBe(true);\n\t});\n\n\ttest('readonly', async ({ page }) => {\n\t\tconst textarea = page.locator('#readonly');\n\t\tawait textarea.pressSequentially('abc');\n\t\tawait expect(textarea).toHaveValue('Cannot be changed');\n\t});\n\n\ttest('autocomplete on/off', async ({ page }) => {\n\t\tconst textareas = [\n\t\t\t{ id: 'autocomplete-off', expected: 'off' },\n\t\t\t{ id: 'autocomplete-on', expected: 'on' },\n\t\t];\n\n\t\tfor (const { id, expected } of textareas) {\n\t\t\tconst host = page.locator(`#${id}`);\n\n\t\t\t// Check host element attribute\n\t\t\tawait expect(host).toHaveAttribute('autocomplete', expected);\n\n\t\t\t// Check shadow DOM textarea element\n\t\t\tconst shadowDomTextarea = await host.evaluate((el: HTMLElement) => {\n\t\t\t\tconst textarea = el.shadowRoot?.querySelector('textarea') as HTMLTextAreaElement | null;\n\t\t\t\treturn textarea?.autocomplete ?? null;\n\t\t\t});\n\t\t\texpect(shadowDomTextarea).toBe(expected);\n\t\t}\n\t});\n\n\ttest('can be combined with external control of value attribute', async ({ page }) => {\n\t\tconst textAreaInsideShadowDOM = page.getByRole('textbox', { name: 'Text area in React' });\n\t\tawait expect(textAreaInsideShadowDOM).toHaveValue('Initial text');\n\n\t\t// First clear and then type in the text area\n\t\tawait textAreaInsideShadowDOM.clear();\n\t\tawait textAreaInsideShadowDOM.fill('Something typed into the form');\n\t\tawait expect(textAreaInsideShadowDOM).toHaveValue('Something typed into the form');\n\n\t\t// Then click the button to change the text to \"Text set in React\"\n\t\tconst reactButton = page.locator('#react-button');\n\t\tawait reactButton.click();\n\n\t\tawait expect(textAreaInsideShadowDOM).toHaveValue('Text set with React');\n\t});\n});\n"]}
@@ -141,7 +141,7 @@ let SDSTextField = class SDSTextField extends LitElement {
141
141
  ?disabled="${this.disabled}"
142
142
  ?readonly="${this.readOnly}"
143
143
  placeholder="${ifDefined(this.placeholder)}"
144
- value="${ifDefined(this.value)}"
144
+ .value="${this.value ?? ''}"
145
145
  name="${ifDefined(this.name)}"
146
146
  autocomplete="${ifDefined(this.autocomplete)}"
147
147
  ?required="${this.required}"
@@ -1 +1 @@
1
- {"version":3,"file":"sds-textfield.js","sourceRoot":"","sources":["../../src/sds-textfield/sds-textfield.ts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AkB;AACjB;IAA1C,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;+CAAoB;AACnB;IAA1C,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;+CAAoB;AAG7C;IAAhB,KAAK,EAAE;6CAAyB;AAER;IAAxB,KAAK,CAAC,gBAAgB,CAAC;6CAA4B;AAtBxC,YAAY;IADxB,oBAAoB,CAAC,eAAe,CAAC;GACzB,YAAY,CAyLxB","sourcesContent":["import { LitElement, html, nothing } from 'lit';\nimport { property, state, query } from 'lit/decorators.js';\nimport { ifDefined } from 'lit/directives/if-defined.js';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { guardedCustomElement } from '../utils/guarded-custom-element';\nimport { styles } from './sds-textfield.styles';\n\nimport '../sds-icon/sds-icon';\nimport { renderErrorMessage } from '../utils/renderErrorMessage';\n\ntype InputType = 'text' | 'email' | 'tel' | 'number' | 'password' | 'search' | 'url';\nexport type AutocompleteTypes =\n\t| 'off'\n\t| 'on'\n\t| 'name'\n\t| 'honorific-prefix'\n\t| 'given-name'\n\t| 'additional-name'\n\t| 'family-name'\n\t| 'honorific-suffix'\n\t| 'nickname'\n\t| 'email'\n\t| 'username'\n\t| 'new-password'\n\t| 'current-password'\n\t| 'one-time-code'\n\t| 'organization-title'\n\t| 'organization'\n\t| 'street-address'\n\t| 'address-line1'\n\t| 'address-line2'\n\t| 'address-line3'\n\t| 'address-level4'\n\t| 'address-level3'\n\t| 'address-level2'\n\t| 'address-level1'\n\t| 'country'\n\t| 'country-name'\n\t| 'postal-code'\n\t| 'cc-name'\n\t| 'cc-given-name'\n\t| 'cc-additional-name'\n\t| 'cc-family-name'\n\t| 'cc-number'\n\t| 'cc-exp'\n\t| 'cc-exp-month'\n\t| 'cc-exp-year'\n\t| 'cc-csc'\n\t| 'cc-type'\n\t| 'transaction-currency'\n\t| 'transaction-amount'\n\t| 'language'\n\t| 'bday'\n\t| 'bday-day'\n\t| 'bday-month'\n\t| 'bday-year'\n\t| 'sex'\n\t| 'tel'\n\t| 'tel-country-code'\n\t| 'tel-national'\n\t| 'tel-area-code'\n\t| 'tel-local'\n\t| 'tel-extension'\n\t| 'impp'\n\t| 'url'\n\t| 'photo';\n\nexport interface SDSTextFieldProps {\n\ttype?: InputType;\n\tvalue?: string;\n\tname?: string;\n\tlabel?: string;\n\tplaceholder?: string;\n\t'help-text'?: string;\n\t'error-message'?: string;\n\tdisabled?: boolean;\n\treadonly?: boolean;\n\tautocomplete?: AutocompleteTypes;\n\trequired?: boolean;\n\tpattern?: string;\n\tminlength?: number;\n\tmaxlength?: number;\n\tonInput?: (event: Event) => void;\n\tonChange?: (event: Event) => void;\n\tonSelect?: (event: Event) => void;\n\tonFocus?: (event: Event) => void;\n\tonBlur?: (event: Event) => void;\n}\n\n@guardedCustomElement('sds-textfield')\nexport class SDSTextField extends LitElement {\n\t// Styling\n\tstatic override styles = [styles];\n\n\t@property({ type: String, reflect: true }) type: InputType = 'text';\n\t@property({ type: String }) value?: string;\n\t@property({ type: String, reflect: true }) name?: string;\n\t@property({ type: String, reflect: true }) label?: string;\n\t@property({ type: String, reflect: true }) placeholder?: string;\n\t@property({ type: String, attribute: 'help-text', reflect: true }) helpText?: string;\n\t@property({ type: String, attribute: 'error-message', reflect: true }) errorMessage?: string;\n\t@property({ type: Boolean, reflect: true }) disabled: boolean = false;\n\t@property({ type: Boolean, attribute: 'readonly', reflect: true }) readOnly: boolean = false;\n\t@property({ type: String, reflect: true }) autocomplete?: AutocompleteTypes;\n\t@property({ type: Boolean, reflect: true }) required: boolean = false;\n\t@property({ type: String, reflect: true }) pattern?: string;\n\t@property({ type: Number, reflect: true }) minlength?: number;\n\t@property({ type: Number, reflect: true }) maxlength?: number;\n\n\t// State\n\t@state() private hasIcon = false;\n\n\t@query('#sds-textfield') control!: HTMLInputElement;\n\n\tstatic formAssociated = true;\n\tpublic readonly internals: ElementInternals;\n\n\tprivate _defaultValue: string = '';\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.internals = this.attachInternals();\n\t\tthis.attachShadow({ mode: 'open', delegatesFocus: true });\n\t}\n\n\toverride connectedCallback() {\n\t\tsuper.connectedCallback();\n\t\tthis._defaultValue = this.value ?? '';\n\t}\n\n\tprivate readonly handleSlotChange = (e: Event) => {\n\t\tconst slot = e.target as HTMLSlotElement;\n\t\tthis.hasIcon = slot.assignedNodes({ flatten: true }).length > 0;\n\t};\n\n\tprivate updateValidity() {\n\t\tif (this.control.checkValidity()) {\n\t\t\tthis.internals.setValidity({});\n\t\t} else {\n\t\t\tthis.internals.setValidity({ customError: true }, this.control.validationMessage, this.control);\n\t\t}\n\t}\n\n\tprivate readonly _handleInputChange = (event: Event) => {\n\t\tevent.stopImmediatePropagation();\n\t\tif (!this.disabled) {\n\t\t\tconst currentValue = (event.target as HTMLInputElement).value;\n\t\t\tthis.value = currentValue;\n\t\t\tthis.internals.setFormValue(currentValue === '' ? null : currentValue);\n\t\t\tthis.updateValidity();\n\t\t\tthis.dispatchEvent(new CustomEvent(event.type, { bubbles: true, composed: true }));\n\t\t}\n\t};\n\n\tprivate readonly _handleSelect = (event: Event) => {\n\t\tevent.stopImmediatePropagation();\n\t\tif (!this.disabled) {\n\t\t\tthis.dispatchEvent(new CustomEvent('select', { bubbles: true, composed: true }));\n\t\t}\n\t};\n\n\tprivate readonly _handleFocus = (event: FocusEvent) => {\n\t\tevent.stopImmediatePropagation();\n\t\tthis.dispatchEvent(new CustomEvent('focus', { bubbles: true, composed: true }));\n\t};\n\n\tprivate readonly _handleBlur = (event: FocusEvent) => {\n\t\tevent.stopImmediatePropagation();\n\t\tthis.updateValidity();\n\t\tthis.dispatchEvent(new CustomEvent('blur', { bubbles: true, composed: true }));\n\t};\n\n\tformResetCallback() {\n\t\tthis.control.value = this._defaultValue;\n\t\tthis.internals.setFormValue(this._defaultValue === '' ? null : this._defaultValue);\n\t\tthis.value = this._defaultValue;\n\t\tthis.updateValidity();\n\t}\n\n\tselect(): void {\n\t\tif (!this.disabled) this.control.select();\n\t}\n\n\toverride focus(): void {\n\t\tif (!this.disabled) this.control.focus();\n\t}\n\n\toverride blur(): void {\n\t\tif (!this.disabled) this.control.blur();\n\t}\n\n\toverride click(): void {\n\t\tif (!this.disabled) this.control.click();\n\t}\n\n\tget selectionStart(): number | null {\n\t\treturn this.control ? this.control.selectionStart : null;\n\t}\n\n\tset selectionStart(value: number | null) {\n\t\tif (this.control && value !== null) {\n\t\t\tthis.control.selectionStart = value;\n\t\t}\n\t}\n\n\tget selectionEnd(): number | null {\n\t\treturn this.control ? this.control.selectionEnd : null;\n\t}\n\tset selectionEnd(value: number | null) {\n\t\tif (this.control && value !== null) {\n\t\t\tthis.control.selectionEnd = value;\n\t\t}\n\t}\n\n\tsetSelectionRange(start: number, end: number, direction?: 'forward' | 'backward' | 'none'): void {\n\t\tif (this.control) {\n\t\t\tthis.control.setSelectionRange(start, end, direction);\n\t\t}\n\t}\n\n\tcheckValidity(): boolean {\n\t\treturn this.control.checkValidity();\n\t}\n\n\treportValidity(): boolean {\n\t\treturn this.control.reportValidity();\n\t}\n\n\tsetCustomValidity(message: string): void {\n\t\tthis.control.setCustomValidity(message);\n\t\tthis.updateValidity();\n\t}\n\n\toverride render() {\n\t\tconst textfieldClasses = {\n\t\t\t'sds-textfield': true,\n\t\t\t'sds-textfield--error': Boolean(this.errorMessage),\n\t\t\t'sds-textfield--disabled': Boolean(this.disabled),\n\t\t\t'sds-textfield--readonly': Boolean(this.readOnly),\n\t\t\t'sds-textfield--has-icon': this.hasIcon,\n\t\t};\n\n\t\treturn html`\n\t\t\t<div class=\"${classMap(textfieldClasses)}\">\n\t\t\t\t${this.label\n\t\t\t\t\t? html`<label for=\"sds-textfield\" class=\"sds-textfield__label\">${this.label}</label>`\n\t\t\t\t\t: nothing}\n\t\t\t\t${this.helpText ? html`<p class=\"sds-textfield__help-text\">${this.helpText}</p>` : nothing}\n\t\t\t\t<div class=\"sds-textfield__input-container\">\n\t\t\t\t\t<input\n\t\t\t\t\t\tclass=\"sds-textfield__input\"\n\t\t\t\t\t\ttype=\"${this.type}\"\n\t\t\t\t\t\tid=\"sds-textfield\"\n\t\t\t\t\t\t?disabled=\"${this.disabled}\"\n\t\t\t\t\t\t?readonly=\"${this.readOnly}\"\n\t\t\t\t\t\tplaceholder=\"${ifDefined(this.placeholder)}\"\n\t\t\t\t\t\tvalue=\"${ifDefined(this.value)}\"\n\t\t\t\t\t\tname=\"${ifDefined(this.name)}\"\n\t\t\t\t\t\tautocomplete=\"${ifDefined(this.autocomplete as any)}\"\n\t\t\t\t\t\t?required=\"${this.required}\"\n\t\t\t\t\t\tpattern=\"${ifDefined(this.pattern)}\"\n\t\t\t\t\t\tminlength=\"${ifDefined(this.minlength)}\"\n\t\t\t\t\t\tmaxlength=\"${ifDefined(this.maxlength)}\"\n\t\t\t\t\t\t@input=\"${this._handleInputChange}\"\n\t\t\t\t\t\t@change=\"${this._handleInputChange}\"\n\t\t\t\t\t\t@select=\"${this._handleSelect}\"\n\t\t\t\t\t\t@focus=\"${this._handleFocus}\"\n\t\t\t\t\t\t@blur=\"${this._handleBlur}\"\n\t\t\t\t\t/>\n\t\t\t\t\t<slot name=\"after\" @slotchange=\"${this.handleSlotChange}\" aria-hidden=\"true\"></slot>\n\t\t\t\t</div>\n\t\t\t\t${renderErrorMessage(this.errorMessage, 'sds-textfield__error-message', this.disabled)}\n\t\t\t</div>\n\t\t`;\n\t}\n}\n\ndeclare global {\n\tinterface HTMLElementTagNameMap {\n\t\t'sds-textfield': SDSTextField;\n\t}\n}\n"]}
1
+ {"version":3,"file":"sds-textfield.js","sourceRoot":"","sources":["../../src/sds-textfield/sds-textfield.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,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IAAI,EAAE,CAAC;+CAAoB;AAG7C;IAAhB,KAAK,EAAE;6CAAyB;AAER;IAAxB,KAAK,CAAC,gBAAgB,CAAC;6CAA4B;AAtBxC,YAAY;IADxB,oBAAoB,CAAC,eAAe,CAAC;GACzB,YAAY,CAyLxB","sourcesContent":["import { LitElement, html, nothing } from 'lit';\nimport { property, state, query } from 'lit/decorators.js';\nimport { ifDefined } from 'lit/directives/if-defined.js';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { guardedCustomElement } from '../utils/guarded-custom-element';\nimport { styles } from './sds-textfield.styles';\n\nimport '../sds-icon/sds-icon';\nimport { renderErrorMessage } from '../utils/renderErrorMessage';\n\ntype InputType = 'text' | 'email' | 'tel' | 'number' | 'password' | 'search' | 'url';\nexport type AutocompleteTypes =\n\t| 'off'\n\t| 'on'\n\t| 'name'\n\t| 'honorific-prefix'\n\t| 'given-name'\n\t| 'additional-name'\n\t| 'family-name'\n\t| 'honorific-suffix'\n\t| 'nickname'\n\t| 'email'\n\t| 'username'\n\t| 'new-password'\n\t| 'current-password'\n\t| 'one-time-code'\n\t| 'organization-title'\n\t| 'organization'\n\t| 'street-address'\n\t| 'address-line1'\n\t| 'address-line2'\n\t| 'address-line3'\n\t| 'address-level4'\n\t| 'address-level3'\n\t| 'address-level2'\n\t| 'address-level1'\n\t| 'country'\n\t| 'country-name'\n\t| 'postal-code'\n\t| 'cc-name'\n\t| 'cc-given-name'\n\t| 'cc-additional-name'\n\t| 'cc-family-name'\n\t| 'cc-number'\n\t| 'cc-exp'\n\t| 'cc-exp-month'\n\t| 'cc-exp-year'\n\t| 'cc-csc'\n\t| 'cc-type'\n\t| 'transaction-currency'\n\t| 'transaction-amount'\n\t| 'language'\n\t| 'bday'\n\t| 'bday-day'\n\t| 'bday-month'\n\t| 'bday-year'\n\t| 'sex'\n\t| 'tel'\n\t| 'tel-country-code'\n\t| 'tel-national'\n\t| 'tel-area-code'\n\t| 'tel-local'\n\t| 'tel-extension'\n\t| 'impp'\n\t| 'url'\n\t| 'photo';\n\nexport interface SDSTextFieldProps {\n\ttype?: InputType;\n\tvalue?: string;\n\tname?: string;\n\tlabel?: string;\n\tplaceholder?: string;\n\t'help-text'?: string;\n\t'error-message'?: string;\n\tdisabled?: boolean;\n\treadonly?: boolean;\n\tautocomplete?: AutocompleteTypes;\n\trequired?: boolean;\n\tpattern?: string;\n\tminlength?: number;\n\tmaxlength?: number;\n\tonInput?: (event: Event) => void;\n\tonChange?: (event: Event) => void;\n\tonSelect?: (event: Event) => void;\n\tonFocus?: (event: Event) => void;\n\tonBlur?: (event: Event) => void;\n}\n\n@guardedCustomElement('sds-textfield')\nexport class SDSTextField extends LitElement {\n\t// Styling\n\tstatic override styles = [styles];\n\n\t@property({ type: String, reflect: true }) type: InputType = 'text';\n\t@property({ type: String }) value?: string;\n\t@property({ type: String, reflect: true }) name?: string;\n\t@property({ type: String, reflect: true }) label?: string;\n\t@property({ type: String, reflect: true }) placeholder?: string;\n\t@property({ type: String, attribute: 'help-text', reflect: true }) helpText?: string;\n\t@property({ type: String, attribute: 'error-message', reflect: true }) errorMessage?: string;\n\t@property({ type: Boolean, reflect: true }) disabled: boolean = false;\n\t@property({ type: Boolean, attribute: 'readonly', reflect: true }) readOnly: boolean = false;\n\t@property({ type: String, reflect: true }) autocomplete?: AutocompleteTypes;\n\t@property({ type: Boolean, reflect: true }) required: boolean = false;\n\t@property({ type: String, reflect: true }) pattern?: string;\n\t@property({ type: Number, reflect: true }) minlength?: number;\n\t@property({ type: Number, reflect: true }) maxlength?: number;\n\n\t// State\n\t@state() private hasIcon = false;\n\n\t@query('#sds-textfield') control!: HTMLInputElement;\n\n\tstatic formAssociated = true;\n\tpublic readonly internals: ElementInternals;\n\n\tprivate _defaultValue: string = '';\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.internals = this.attachInternals();\n\t\tthis.attachShadow({ mode: 'open', delegatesFocus: true });\n\t}\n\n\toverride connectedCallback() {\n\t\tsuper.connectedCallback();\n\t\tthis._defaultValue = this.value ?? '';\n\t}\n\n\tprivate readonly handleSlotChange = (e: Event) => {\n\t\tconst slot = e.target as HTMLSlotElement;\n\t\tthis.hasIcon = slot.assignedNodes({ flatten: true }).length > 0;\n\t};\n\n\tprivate updateValidity() {\n\t\tif (this.control.checkValidity()) {\n\t\t\tthis.internals.setValidity({});\n\t\t} else {\n\t\t\tthis.internals.setValidity({ customError: true }, this.control.validationMessage, this.control);\n\t\t}\n\t}\n\n\tprivate readonly _handleInputChange = (event: Event) => {\n\t\tevent.stopImmediatePropagation();\n\t\tif (!this.disabled) {\n\t\t\tconst currentValue = (event.target as HTMLInputElement).value;\n\t\t\tthis.value = currentValue;\n\t\t\tthis.internals.setFormValue(currentValue === '' ? null : currentValue);\n\t\t\tthis.updateValidity();\n\t\t\tthis.dispatchEvent(new CustomEvent(event.type, { bubbles: true, composed: true }));\n\t\t}\n\t};\n\n\tprivate readonly _handleSelect = (event: Event) => {\n\t\tevent.stopImmediatePropagation();\n\t\tif (!this.disabled) {\n\t\t\tthis.dispatchEvent(new CustomEvent('select', { bubbles: true, composed: true }));\n\t\t}\n\t};\n\n\tprivate readonly _handleFocus = (event: FocusEvent) => {\n\t\tevent.stopImmediatePropagation();\n\t\tthis.dispatchEvent(new CustomEvent('focus', { bubbles: true, composed: true }));\n\t};\n\n\tprivate readonly _handleBlur = (event: FocusEvent) => {\n\t\tevent.stopImmediatePropagation();\n\t\tthis.updateValidity();\n\t\tthis.dispatchEvent(new CustomEvent('blur', { bubbles: true, composed: true }));\n\t};\n\n\tformResetCallback() {\n\t\tthis.control.value = this._defaultValue;\n\t\tthis.internals.setFormValue(this._defaultValue === '' ? null : this._defaultValue);\n\t\tthis.value = this._defaultValue;\n\t\tthis.updateValidity();\n\t}\n\n\tselect(): void {\n\t\tif (!this.disabled) this.control.select();\n\t}\n\n\toverride focus(): void {\n\t\tif (!this.disabled) this.control.focus();\n\t}\n\n\toverride blur(): void {\n\t\tif (!this.disabled) this.control.blur();\n\t}\n\n\toverride click(): void {\n\t\tif (!this.disabled) this.control.click();\n\t}\n\n\tget selectionStart(): number | null {\n\t\treturn this.control ? this.control.selectionStart : null;\n\t}\n\n\tset selectionStart(value: number | null) {\n\t\tif (this.control && value !== null) {\n\t\t\tthis.control.selectionStart = value;\n\t\t}\n\t}\n\n\tget selectionEnd(): number | null {\n\t\treturn this.control ? this.control.selectionEnd : null;\n\t}\n\tset selectionEnd(value: number | null) {\n\t\tif (this.control && value !== null) {\n\t\t\tthis.control.selectionEnd = value;\n\t\t}\n\t}\n\n\tsetSelectionRange(start: number, end: number, direction?: 'forward' | 'backward' | 'none'): void {\n\t\tif (this.control) {\n\t\t\tthis.control.setSelectionRange(start, end, direction);\n\t\t}\n\t}\n\n\tcheckValidity(): boolean {\n\t\treturn this.control.checkValidity();\n\t}\n\n\treportValidity(): boolean {\n\t\treturn this.control.reportValidity();\n\t}\n\n\tsetCustomValidity(message: string): void {\n\t\tthis.control.setCustomValidity(message);\n\t\tthis.updateValidity();\n\t}\n\n\toverride render() {\n\t\tconst textfieldClasses = {\n\t\t\t'sds-textfield': true,\n\t\t\t'sds-textfield--error': Boolean(this.errorMessage),\n\t\t\t'sds-textfield--disabled': Boolean(this.disabled),\n\t\t\t'sds-textfield--readonly': Boolean(this.readOnly),\n\t\t\t'sds-textfield--has-icon': this.hasIcon,\n\t\t};\n\n\t\treturn html`\n\t\t\t<div class=\"${classMap(textfieldClasses)}\">\n\t\t\t\t${this.label\n\t\t\t\t\t? html`<label for=\"sds-textfield\" class=\"sds-textfield__label\">${this.label}</label>`\n\t\t\t\t\t: nothing}\n\t\t\t\t${this.helpText ? html`<p class=\"sds-textfield__help-text\">${this.helpText}</p>` : nothing}\n\t\t\t\t<div class=\"sds-textfield__input-container\">\n\t\t\t\t\t<input\n\t\t\t\t\t\tclass=\"sds-textfield__input\"\n\t\t\t\t\t\ttype=\"${this.type}\"\n\t\t\t\t\t\tid=\"sds-textfield\"\n\t\t\t\t\t\t?disabled=\"${this.disabled}\"\n\t\t\t\t\t\t?readonly=\"${this.readOnly}\"\n\t\t\t\t\t\tplaceholder=\"${ifDefined(this.placeholder)}\"\n\t\t\t\t\t\t.value=\"${this.value ?? ''}\"\n\t\t\t\t\t\tname=\"${ifDefined(this.name)}\"\n\t\t\t\t\t\tautocomplete=\"${ifDefined(this.autocomplete as any)}\"\n\t\t\t\t\t\t?required=\"${this.required}\"\n\t\t\t\t\t\tpattern=\"${ifDefined(this.pattern)}\"\n\t\t\t\t\t\tminlength=\"${ifDefined(this.minlength)}\"\n\t\t\t\t\t\tmaxlength=\"${ifDefined(this.maxlength)}\"\n\t\t\t\t\t\t@input=\"${this._handleInputChange}\"\n\t\t\t\t\t\t@change=\"${this._handleInputChange}\"\n\t\t\t\t\t\t@select=\"${this._handleSelect}\"\n\t\t\t\t\t\t@focus=\"${this._handleFocus}\"\n\t\t\t\t\t\t@blur=\"${this._handleBlur}\"\n\t\t\t\t\t/>\n\t\t\t\t\t<slot name=\"after\" @slotchange=\"${this.handleSlotChange}\" aria-hidden=\"true\"></slot>\n\t\t\t\t</div>\n\t\t\t\t${renderErrorMessage(this.errorMessage, 'sds-textfield__error-message', this.disabled)}\n\t\t\t</div>\n\t\t`;\n\t}\n}\n\ndeclare global {\n\tinterface HTMLElementTagNameMap {\n\t\t'sds-textfield': SDSTextField;\n\t}\n}\n"]}
@@ -135,5 +135,17 @@ test.describe('textfield-component', () => {
135
135
  expect(shadowDomInput).toBe(expected);
136
136
  }
137
137
  });
138
+ test('can be combined with external control of value attribute', async ({ page }) => {
139
+ const textField = page.getByRole('textbox', { name: 'Text field in React' });
140
+ await expect(textField).toHaveValue('Initial text');
141
+ // First clear and then type in the text field
142
+ await textField.clear();
143
+ await textField.fill('Something typed into the form');
144
+ await expect(textField).toHaveValue('Something typed into the form');
145
+ // Then click the button to change the text to "Text set in React"
146
+ const reactButton = page.locator('#react-button');
147
+ await reactButton.click();
148
+ await expect(textField).toHaveValue('Text set with React');
149
+ });
138
150
  });
139
151
  //# sourceMappingURL=sds-textfield.spec.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sds-textfield.spec.js","sourceRoot":"","sources":["../../src/sds-textfield/sds-textfield.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,oCAAoC,CAAC;AAEzE,MAAM,YAAY,GAAG;IACpB,gBAAgB;IAChB,iBAAiB;IACjB,uBAAuB;IACvB,oBAAoB;IACpB,oBAAoB;IACpB,oBAAoB;IACpB,oBAAoB;IACpB,iBAAiB;IACjB,gBAAgB;IAChB,4BAA4B;IAC5B,2BAA2B;IAC3B,mBAAmB;IACnB,eAAe;IACf,eAAe;CACf,CAAC;AAEF,MAAM,OAAO,GAAG,mDAAmD,CAAC;AAEpE,IAAI,CAAC,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACzC,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE;QAClC,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC1B,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,YAAY,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE;QACrC,KAAK,MAAM,EAAE,IAAI,YAAY,EAAE,CAAC;YAC/B,MAAM,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;QACpD,CAAC;IACF,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,uBAAuB,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE;QAChD,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;QAEpB,KAAK,MAAM,EAAE,IAAI,YAAY,EAAE,CAAC;YAC/B,gBAAgB;YAChB,MAAM,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EA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C,UAAU,EAAE,aAAa,CAAC,OAAO,CAA4B,CAAC;gBAC/E,OAAO,KAAK,EAAE,YAAY,IAAI,IAAI,CAAC;YACpC,CAAC,CAAC,CAAC;YACH,MAAM,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACvC,CAAC;IACF,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import { test, expect } from '@playwright/test';\nimport { expect as sdsExpect } from '../playwright-util/custom-matchers';\n\nconst textfieldIds = [\n\t'textfield-name',\n\t'textfield-label',\n\t'textfield-placeholder',\n\t'textfield-helptext',\n\t'textfield-disabled',\n\t'textfield-readonly',\n\t'textfield-required',\n\t'textfield-error',\n\t'textfield-icon',\n\t'textfield-autocomplete-off',\n\t'textfield-autocomplete-on',\n\t'textfield-pattern',\n\t'textfield-min',\n\t'textfield-max',\n];\n\nconst pageUrl = 'iframe.html?viewMode=docs&id=test-textfield--docs';\n\ntest.describe('textfield-component', () => {\n\ttest.beforeEach(async ({ page }) => {\n\t\tawait page.goto(pageUrl);\n\t});\n\n\ttest('visibility', async ({ page }) => {\n\t\tfor (const id of textfieldIds) {\n\t\t\tawait expect(page.locator(`#${id}`)).toBeVisible();\n\t\t}\n\t});\n\n\ttest('design-implementation', async ({ page }) => {\n\t\tawait page.reload();\n\n\t\tfor (const id of textfieldIds) {\n\t\t\t// Default state\n\t\t\tawait expect(page.locator(`#${id}`)).toHaveScreenshot(`${id}.png`);\n\t\t\t// Hover state\n\t\t\tpage.locator(`#${id}`).hover();\n\t\t\tawait expect(page.locator(`#${id}`)).toHaveScreenshot(`${id}-hover.png`);\n\t\t\t// Focus state\n\t\t\tawait page.evaluate((id) => {\n\t\t\t\tconst element = document.getElementById(id);\n\t\t\t\tif (element) {\n\t\t\t\t\tconst parentDiv = document.createElement('div');\n\t\t\t\t\tparentDiv.style.padding = '10px';\n\t\t\t\t\tparentDiv.style.backgroundColor = 'white';\n\t\t\t\t\telement.parentNode?.insertBefore(parentDiv, element);\n\t\t\t\t\tparentDiv.appendChild(element);\n\t\t\t\t}\n\t\t\t}, id);\n\t\t\tpage.locator(`#${id}`).focus();\n\t\t\tconst parentDiv = await page.locator(`#${id}`).locator('xpath=..');\n\t\t\tawait expect(parentDiv).toHaveScreenshot(`${id}-focus.png`);\n\t\t}\n\t});\n\n\ttest('form-submission', async ({ page }) => {\n\t\tlet requestUrl: URL | undefined;\n\t\tpage.on('request', (request) => {\n\t\t\tif (request.url().includes('iframe.html?name=John')) {\n\t\t\t\trequestUrl = new URL(request.url());\n\t\t\t}\n\t\t});\n\n\t\tawait page.locator('#textfield-name').pressSequentially('John');\n\t\tawait page.locator('#submit-button').click();\n\t\tawait expect(requestUrl?.searchParams.get('name')).toBe('John');\n\t});\n\n\ttest('form-reset', async ({ page }) => {\n\t\tawait page.locator('#textfield-name').pressSequentially('John');\n\t\tawait page.locator('#reset-button').click();\n\t\tconst value = await page.locator('#textfield-name').getAttribute('value');\n\t\texpect(value).toBeNull();\n\t});\n\n\ttest('minlength', async ({ page }) => {\n\t\tconst textfield = page.locator('#textfield-min');\n\n\t\tawait textfield.pressSequentially('abc');\n\t\tconst isValidShort = await textfield.evaluate((el: HTMLInputElement) => el.checkValidity());\n\t\texpect(isValidShort).toBe(false);\n\n\t\tawait page.goto(pageUrl);\n\t\tawait textfield.pressSequentially('abcd');\n\t\tconst isValidExact = await textfield.evaluate((el: HTMLInputElement) => el.checkValidity());\n\t\texpect(isValidExact).toBe(true);\n\t});\n\n\ttest('maxlength', async ({ page }) => {\n\t\tconst textfield = page.locator('#textfield-max');\n\n\t\tawait textfield.pressSequentially('abcdef');\n\t\tawait sdsExpect(textfield).toHaveValue('abcd');\n\t});\n\n\ttest('pattern', async ({ page }) => {\n\t\tconst textfield = page.locator('#textfield-pattern');\n\n\t\t// Non-digits → invalid\n\t\tawait textfield.pressSequentially('abcd');\n\t\tlet isValid = await textfield.evaluate((el: HTMLInputElement) => el.checkValidity());\n\t\texpect(isValid).toBe(false);\n\n\t\t// Too few digits → invalid\n\t\tawait page.goto(pageUrl);\n\t\tawait textfield.pressSequentially('123');\n\t\tisValid = await textfield.evaluate((el: HTMLInputElement) => el.checkValidity());\n\t\texpect(isValid).toBe(false);\n\n\t\t// Exactly 4 digits → valid\n\t\tawait page.goto(pageUrl);\n\t\tawait textfield.pressSequentially('1234');\n\t\tisValid = await textfield.evaluate((el: HTMLInputElement) => el.checkValidity());\n\t\texpect(isValid).toBe(true);\n\n\t\t// Too many digits → invalid\n\t\tawait page.goto(pageUrl);\n\t\tawait textfield.pressSequentially('12345');\n\t\tisValid = await textfield.evaluate((el: HTMLInputElement) => el.checkValidity());\n\t\texpect(isValid).toBe(false);\n\t});\n\n\ttest('required', async ({ page }) => {\n\t\tconst textfield = page.locator('#textfield-required');\n\n\t\t// No value → invalid\n\t\tlet isValid = await textfield.evaluate((el: HTMLInputElement) => el.checkValidity());\n\t\texpect(isValid).toBe(false);\n\n\t\t// Has value → valid\n\t\tawait page.goto(pageUrl);\n\t\tawait textfield.pressSequentially('abc');\n\t\tisValid = await textfield.evaluate((el: HTMLInputElement) => el.checkValidity());\n\t\texpect(isValid).toBe(true);\n\t});\n\n\ttest('readonly', async ({ page }) => {\n\t\tconst textfield = page.locator('#textfield-readonly');\n\t\tawait textfield.pressSequentially('abc');\n\t\tawait sdsExpect(textfield).toHaveValue('Kan ikke endres');\n\t});\n\n\ttest('autocomplete on/off', async ({ page }) => {\n\t\tconst textfields = [\n\t\t\t{ id: 'textfield-autocomplete-off', expected: 'off' },\n\t\t\t{ id: 'textfield-autocomplete-on', expected: 'on' },\n\t\t];\n\n\t\tfor (const { id, expected } of textfields) {\n\t\t\tconst host = page.locator(`#${id}`);\n\n\t\t\tawait expect(host).toHaveAttribute('autocomplete', expected);\n\t\t\tconst shadowDomInput = await host.evaluate((el: HTMLElement) => {\n\t\t\t\tconst input = el.shadowRoot?.querySelector('input') as HTMLInputElement | null;\n\t\t\t\treturn input?.autocomplete ?? null;\n\t\t\t});\n\t\t\texpect(shadowDomInput).toBe(expected);\n\t\t}\n\t});\n});\n"]}
1
+ {"version":3,"file":"sds-textfield.spec.js","sourceRoot":"","sources":["../../src/sds-textfield/sds-textfield.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,oCAAoC,CAAC;AAEzE,MAAM,YAAY,GAAG;IACpB,gBAAgB;IAChB,iBAAiB;IACjB,uBAAuB;IACvB,oBAAoB;IACpB,oBAAoB;IACpB,oBAAoB;IACpB,oBAAoB;IACpB,iBAAiB;IACjB,gBAAgB;IAChB,4BAA4B;IAC5B,2BAA2B;IAC3B,mBAAmB;IACnB,eAAe;IACf,eAAe;CACf,CAAC;AAEF,MAAM,OAAO,GAAG,mDAAmD,CAAC;AAEpE,IAAI,CAAC,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACzC,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE;QAClC,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC1B,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,YAAY,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE;QACrC,KAAK,MAAM,EAAE,IAAI,YAAY,EAAE,CAAC;YAC/B,MAAM,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;QACpD,CAAC;IACF,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,uBAAuB,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE;QAChD,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;QAEpB,KAAK,MAAM,EAAE,IAAI,YAAY,EAAE,CAAC;YAC/B,gBAAgB;YAChB,MAAM,MAAM,CAAC,IAAI,C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AM,KAAK,GAAG,EAAE,CAAC,UAAU,EAAE,aAAa,CAAC,OAAO,CAA4B,CAAC;gBAC/E,OAAO,KAAK,EAAE,YAAY,IAAI,IAAI,CAAC;YACpC,CAAC,CAAC,CAAC;YACH,MAAM,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACvC,CAAC;IACF,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,0DAA0D,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE;QACnF,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,EAAE,IAAI,EAAE,qBAAqB,EAAE,CAAC,CAAC;QAC7E,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;QAEpD,8CAA8C;QAC9C,MAAM,SAAS,CAAC,KAAK,EAAE,CAAC;QACxB,MAAM,SAAS,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC;QACtD,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC,WAAW,CAAC,+BAA+B,CAAC,CAAC;QAErE,kEAAkE;QAClE,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;QAClD,MAAM,WAAW,CAAC,KAAK,EAAE,CAAC;QAE1B,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC,WAAW,CAAC,qBAAqB,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import { test, expect } from '@playwright/test';\nimport { expect as sdsExpect } from '../playwright-util/custom-matchers';\n\nconst textfieldIds = [\n\t'textfield-name',\n\t'textfield-label',\n\t'textfield-placeholder',\n\t'textfield-helptext',\n\t'textfield-disabled',\n\t'textfield-readonly',\n\t'textfield-required',\n\t'textfield-error',\n\t'textfield-icon',\n\t'textfield-autocomplete-off',\n\t'textfield-autocomplete-on',\n\t'textfield-pattern',\n\t'textfield-min',\n\t'textfield-max',\n];\n\nconst pageUrl = 'iframe.html?viewMode=docs&id=test-textfield--docs';\n\ntest.describe('textfield-component', () => {\n\ttest.beforeEach(async ({ page }) => {\n\t\tawait page.goto(pageUrl);\n\t});\n\n\ttest('visibility', async ({ page }) => {\n\t\tfor (const id of textfieldIds) {\n\t\t\tawait expect(page.locator(`#${id}`)).toBeVisible();\n\t\t}\n\t});\n\n\ttest('design-implementation', async ({ page }) => {\n\t\tawait page.reload();\n\n\t\tfor (const id of textfieldIds) {\n\t\t\t// Default state\n\t\t\tawait expect(page.locator(`#${id}`)).toHaveScreenshot(`${id}.png`);\n\t\t\t// Hover state\n\t\t\tpage.locator(`#${id}`).hover();\n\t\t\tawait expect(page.locator(`#${id}`)).toHaveScreenshot(`${id}-hover.png`);\n\t\t\t// Focus state\n\t\t\tawait page.evaluate((id) => {\n\t\t\t\tconst element = document.getElementById(id);\n\t\t\t\tif (element) {\n\t\t\t\t\tconst parentDiv = document.createElement('div');\n\t\t\t\t\tparentDiv.style.padding = '10px';\n\t\t\t\t\tparentDiv.style.backgroundColor = 'white';\n\t\t\t\t\telement.parentNode?.insertBefore(parentDiv, element);\n\t\t\t\t\tparentDiv.appendChild(element);\n\t\t\t\t}\n\t\t\t}, id);\n\t\t\tpage.locator(`#${id}`).focus();\n\t\t\tconst parentDiv = await page.locator(`#${id}`).locator('xpath=..');\n\t\t\tawait expect(parentDiv).toHaveScreenshot(`${id}-focus.png`);\n\t\t}\n\t});\n\n\ttest('form-submission', async ({ page }) => {\n\t\tlet requestUrl: URL | undefined;\n\t\tpage.on('request', (request) => {\n\t\t\tif (request.url().includes('iframe.html?name=John')) {\n\t\t\t\trequestUrl = new URL(request.url());\n\t\t\t}\n\t\t});\n\n\t\tawait page.locator('#textfield-name').pressSequentially('John');\n\t\tawait page.locator('#submit-button').click();\n\t\tawait expect(requestUrl?.searchParams.get('name')).toBe('John');\n\t});\n\n\ttest('form-reset', async ({ page }) => {\n\t\tawait page.locator('#textfield-name').pressSequentially('John');\n\t\tawait page.locator('#reset-button').click();\n\t\tconst value = await page.locator('#textfield-name').getAttribute('value');\n\t\texpect(value).toBeNull();\n\t});\n\n\ttest('minlength', async ({ page }) => {\n\t\tconst textfield = page.locator('#textfield-min');\n\n\t\tawait textfield.pressSequentially('abc');\n\t\tconst isValidShort = await textfield.evaluate((el: HTMLInputElement) => el.checkValidity());\n\t\texpect(isValidShort).toBe(false);\n\n\t\tawait page.goto(pageUrl);\n\t\tawait textfield.pressSequentially('abcd');\n\t\tconst isValidExact = await textfield.evaluate((el: HTMLInputElement) => el.checkValidity());\n\t\texpect(isValidExact).toBe(true);\n\t});\n\n\ttest('maxlength', async ({ page }) => {\n\t\tconst textfield = page.locator('#textfield-max');\n\n\t\tawait textfield.pressSequentially('abcdef');\n\t\tawait sdsExpect(textfield).toHaveValue('abcd');\n\t});\n\n\ttest('pattern', async ({ page }) => {\n\t\tconst textfield = page.locator('#textfield-pattern');\n\n\t\t// Non-digits → invalid\n\t\tawait textfield.pressSequentially('abcd');\n\t\tlet isValid = await textfield.evaluate((el: HTMLInputElement) => el.checkValidity());\n\t\texpect(isValid).toBe(false);\n\n\t\t// Too few digits → invalid\n\t\tawait page.goto(pageUrl);\n\t\tawait textfield.pressSequentially('123');\n\t\tisValid = await textfield.evaluate((el: HTMLInputElement) => el.checkValidity());\n\t\texpect(isValid).toBe(false);\n\n\t\t// Exactly 4 digits → valid\n\t\tawait page.goto(pageUrl);\n\t\tawait textfield.pressSequentially('1234');\n\t\tisValid = await textfield.evaluate((el: HTMLInputElement) => el.checkValidity());\n\t\texpect(isValid).toBe(true);\n\n\t\t// Too many digits → invalid\n\t\tawait page.goto(pageUrl);\n\t\tawait textfield.pressSequentially('12345');\n\t\tisValid = await textfield.evaluate((el: HTMLInputElement) => el.checkValidity());\n\t\texpect(isValid).toBe(false);\n\t});\n\n\ttest('required', async ({ page }) => {\n\t\tconst textfield = page.locator('#textfield-required');\n\n\t\t// No value → invalid\n\t\tlet isValid = await textfield.evaluate((el: HTMLInputElement) => el.checkValidity());\n\t\texpect(isValid).toBe(false);\n\n\t\t// Has value → valid\n\t\tawait page.goto(pageUrl);\n\t\tawait textfield.pressSequentially('abc');\n\t\tisValid = await textfield.evaluate((el: HTMLInputElement) => el.checkValidity());\n\t\texpect(isValid).toBe(true);\n\t});\n\n\ttest('readonly', async ({ page }) => {\n\t\tconst textfield = page.locator('#textfield-readonly');\n\t\tawait textfield.pressSequentially('abc');\n\t\tawait sdsExpect(textfield).toHaveValue('Kan ikke endres');\n\t});\n\n\ttest('autocomplete on/off', async ({ page }) => {\n\t\tconst textfields = [\n\t\t\t{ id: 'textfield-autocomplete-off', expected: 'off' },\n\t\t\t{ id: 'textfield-autocomplete-on', expected: 'on' },\n\t\t];\n\n\t\tfor (const { id, expected } of textfields) {\n\t\t\tconst host = page.locator(`#${id}`);\n\n\t\t\tawait expect(host).toHaveAttribute('autocomplete', expected);\n\t\t\tconst shadowDomInput = await host.evaluate((el: HTMLElement) => {\n\t\t\t\tconst input = el.shadowRoot?.querySelector('input') as HTMLInputElement | null;\n\t\t\t\treturn input?.autocomplete ?? null;\n\t\t\t});\n\t\t\texpect(shadowDomInput).toBe(expected);\n\t\t}\n\t});\n\n\ttest('can be combined with external control of value attribute', async ({ page }) => {\n\t\tconst textField = page.getByRole('textbox', { name: 'Text field in React' });\n\t\tawait expect(textField).toHaveValue('Initial text');\n\n\t\t// First clear and then type in the text field\n\t\tawait textField.clear();\n\t\tawait textField.fill('Something typed into the form');\n\t\tawait expect(textField).toHaveValue('Something typed into the form');\n\n\t\t// Then click the button to change the text to \"Text set in React\"\n\t\tconst reactButton = page.locator('#react-button');\n\t\tawait reactButton.click();\n\n\t\tawait expect(textField).toHaveValue('Text set with React');\n\t});\n});\n"]}
@@ -4080,7 +4080,7 @@ let SDSTextField = class extends i$1 {
4080
4080
  ?disabled="${this.disabled}"
4081
4081
  ?readonly="${this.readOnly}"
4082
4082
  placeholder="${o$1(this.placeholder)}"
4083
- value="${o$1(this.value)}"
4083
+ .value="${this.value ?? ""}"
4084
4084
  name="${o$1(this.name)}"
4085
4085
  autocomplete="${o$1(this.autocomplete)}"
4086
4086
  ?required="${this.required}"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@politiet/sheriff-web-components",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "description": "Sheriff Design System Web Components Library",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",