-
Notifications
You must be signed in to change notification settings - Fork 795
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correctly call proxied formAssociated callbacks
- Loading branch information
Dominique Wirz
committed
Nov 11, 2024
1 parent
4cabb30
commit 4fdbee0
Showing
10 changed files
with
167 additions
and
11 deletions.
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
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
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,15 @@ | ||
import type { Config } from '../../internal/index.js'; | ||
|
||
export const config: Config = { | ||
namespace: 'TestNoExternalRuntimeApp', | ||
tsconfig: 'tsconfig-no-external-runtime.json', | ||
outputTargets: [ | ||
{ | ||
type: 'dist-custom-elements', | ||
dir: 'test-components-no-external-runtime', | ||
externalRuntime: false, | ||
includeGlobalScripts: false, | ||
}, | ||
], | ||
srcDir: 'no-external-runtime', | ||
}; |
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,37 @@ | ||
/* eslint-disable */ | ||
/* tslint:disable */ | ||
/** | ||
* This is an autogenerated file created by the Stencil compiler. | ||
* It contains typing information for all components that exist in this project. | ||
*/ | ||
import { HTMLStencilElement, JSXBase } from "@stencil/core/internal"; | ||
export namespace Components { | ||
interface CustomElementsFormAssociated { | ||
} | ||
} | ||
declare global { | ||
interface HTMLCustomElementsFormAssociatedElement extends Components.CustomElementsFormAssociated, HTMLStencilElement { | ||
} | ||
var HTMLCustomElementsFormAssociatedElement: { | ||
prototype: HTMLCustomElementsFormAssociatedElement; | ||
new (): HTMLCustomElementsFormAssociatedElement; | ||
}; | ||
interface HTMLElementTagNameMap { | ||
"custom-elements-form-associated": HTMLCustomElementsFormAssociatedElement; | ||
} | ||
} | ||
declare namespace LocalJSX { | ||
interface CustomElementsFormAssociated { | ||
} | ||
interface IntrinsicElements { | ||
"custom-elements-form-associated": CustomElementsFormAssociated; | ||
} | ||
} | ||
export { LocalJSX as JSX }; | ||
declare module "@stencil/core" { | ||
export namespace JSX { | ||
interface IntrinsicElements { | ||
"custom-elements-form-associated": LocalJSX.CustomElementsFormAssociated & JSXBase.HTMLAttributes<HTMLCustomElementsFormAssociatedElement>; | ||
} | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
test/wdio/no-external-runtime/custom-elements-form-associated/cmp.test.tsx
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,67 @@ | ||
import { h } from '@stencil/core'; | ||
import { render } from '@wdio/browser-runner/stencil'; | ||
|
||
import { defineCustomElement } from '../../test-components-no-external-runtime/custom-elements-form-associated.js'; | ||
|
||
describe('custome elements form associated', function () { | ||
beforeEach(() => { | ||
defineCustomElement(); | ||
render({ | ||
template: () => ( | ||
<form> | ||
<custom-elements-form-associated name="test-input"></custom-elements-form-associated> | ||
<input type="reset" value="Reset" /> | ||
</form> | ||
), | ||
}); | ||
}); | ||
|
||
it('should render without errors', async () => { | ||
const elm = $('custom-elements-form-associated'); | ||
await expect(elm).toBePresent(); | ||
}); | ||
|
||
describe('form associated custom element lifecycle callback', () => { | ||
it('should trigger "formAssociated"', async () => { | ||
const formEl = $('form'); | ||
await expect(formEl).toHaveProperty('ariaLabel', 'asdfasdf'); | ||
}); | ||
|
||
it('should trigger "formResetCallback"', async () => { | ||
const resetBtn = $('input[type="reset"]'); | ||
await resetBtn.click(); | ||
|
||
await resetBtn.waitForStable(); | ||
|
||
const formEl = $('form'); | ||
await expect(formEl).toHaveProperty('ariaLabel', 'formResetCallback called'); | ||
}); | ||
|
||
it('should trigger "formDisabledCallback"', async () => { | ||
const elm = document.body.querySelector('custom-elements-form-associated'); | ||
const formEl = $('form'); | ||
|
||
elm.setAttribute('disabled', 'disabled'); | ||
|
||
await formEl.waitForStable(); | ||
await expect(formEl).toHaveProperty('ariaLabel', 'formDisabledCallback called with true'); | ||
|
||
elm.removeAttribute('disabled'); | ||
await formEl.waitForStable(); | ||
await expect(formEl).toHaveProperty('ariaLabel', 'formDisabledCallback called with false'); | ||
}); | ||
}); | ||
|
||
it('should link up to the surrounding form', async () => { | ||
// this shows that the element has, through the `ElementInternals` | ||
// interface, been able to set a value in the surrounding form | ||
await browser.waitUntil( | ||
async () => { | ||
const formEl = document.body.querySelector('form'); | ||
expect(new FormData(formEl).get('test-input')).toBe('my default value'); | ||
return true; | ||
}, | ||
{ timeoutMsg: 'form associated value never changed' }, | ||
); | ||
}); | ||
}); |
25 changes: 25 additions & 0 deletions
25
test/wdio/no-external-runtime/custom-elements-form-associated/cmp.tsx
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,25 @@ | ||
import { AttachInternals, Component, h } from '@stencil/core'; | ||
|
||
@Component({ | ||
tag: 'custom-elements-form-associated', | ||
formAssociated: true, | ||
shadow: true, | ||
}) | ||
export class CustomElementsFormAssociated { | ||
@AttachInternals() internals: ElementInternals; | ||
|
||
componentWillLoad() { | ||
this.internals.setFormValue('my default value'); | ||
} | ||
|
||
formAssociatedCallback(form: HTMLCustomElementsFormAssociatedElement) { | ||
form.ariaLabel = 'formAssociated called'; | ||
// this is a regression test for #5106 which ensures that `this` is | ||
// resolved correctly | ||
this.internals.setValidity({}); | ||
} | ||
|
||
render() { | ||
return <input type="text" />; | ||
} | ||
} |
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
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
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,5 @@ | ||
{ | ||
"extends": "./tsconfig-stencil.json", | ||
"include": ["no-external-runtime"], | ||
"exclude": ["no-external-runtime/**/*.test.tsx"] | ||
} |
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