Skip to content

Commit

Permalink
fix: form participation fixes (#411)
Browse files Browse the repository at this point in the history
  • Loading branch information
muratcorlu authored Feb 10, 2023
1 parent 0304e49 commit 51e2725
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 36 deletions.
42 changes: 21 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@
"@floating-ui/dom": "^0.5.4",
"@fontsource/rubik": "^4.5.9",
"@lit-labs/react": "^1.1.0",
"@open-wc/form-control": "^0.4.1",
"@open-wc/form-helpers": "^0.1.2",
"element-internals-polyfill": "^1.1.15",
"@open-wc/form-control": "^0.5.1",
"@open-wc/form-helpers": "^0.2.1",
"element-internals-polyfill": "^1.2.3",
"lit": "^2.2.3"
},
"engines": {
Expand Down
7 changes: 3 additions & 4 deletions src/components/drawer/bl-drawer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,14 @@ describe('bl-drawer',() => {
});

it('should render the caption, embedUrl if provided', async ()=>{
const el = await fixture<typeOfBlDrawer>(html`<bl-drawer caption="My Caption" embed-url="some-url" open><div>example content</div></bl-drawer>`);
const embedUrl = '/?test=1';
const el = await fixture<typeOfBlDrawer>(html`<bl-drawer caption="My Caption" embed-url="${embedUrl}" open><div>example content</div></bl-drawer>`);

const caption = el.shadowRoot?.querySelector('#drawer-caption') as HTMLElement;
const iframeEl = el.shadowRoot?.querySelector('iframe') as HTMLElement;

expect(iframeEl).to.exist;
expect(iframeEl.attributes.getNamedItem('src')?.value).to.contain("some-url");
expect(iframeEl.attributes.getNamedItem('src')?.value).to.contain(embedUrl);

expect(caption).to.exist;
expect(caption.innerText).to.equal('My Caption');
Expand Down Expand Up @@ -129,7 +130,6 @@ describe('bl-drawer',() => {
setTimeout(async () => {
const openEvent = await oneEvent(el,'bl-drawer-open');
expect(openEvent).to.exist;
expect(openEvent.detail.isOpen).to.equal(true);
});
});
it('should fire bl-drawer-close when dialog closes',async ()=>{
Expand All @@ -141,7 +141,6 @@ describe('bl-drawer',() => {
closeBtn?.click();
const openEvent = await oneEvent(el,'bl-drawer-close');
expect(openEvent).to.exist;
expect(openEvent.detail.isOpen).to.equal(false);
});
});
})
Expand Down
2 changes: 1 addition & 1 deletion src/components/textarea/bl-textarea.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ describe('bl-textarea', () => {

const ev = await oneEvent(el, 'bl-invalid');
expect(ev).to.exist;
expect(ev.detail['rangeOverflow']).to.equal(true);
expect(ev.detail['tooLong']).to.equal(true);
});
});
describe('form integration', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/textarea/bl-textarea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export default class BlTextarea extends FormControlMixin(LitElement) {
@state() private dirty = false;

render(): TemplateResult {
const maxLengthInvalid = this.internals.validity.rangeOverflow;
const maxLengthInvalid = this.internals.validity.tooLong;
const invalidMessage = !this.checkValidity()
? html`<p class="invalid-text">${this.validationMessage}</p>`
: ``;
Expand Down
11 changes: 5 additions & 6 deletions src/utilities/form-control.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {maxLengthValidator, requiredValidator} from "@open-wc/form-control";
import { maxLengthValidator } from "@open-wc/form-control";


const validityStates: Array<keyof ValidityState> = [
Expand All @@ -25,15 +25,14 @@ export const innerInputValidators = validityStates.map(key => ({
export const textareaLengthValidator = {
...maxLengthValidator,
isValid(instance: HTMLElement & { validationTarget: HTMLTextAreaElement }) {
if(instance.validationTarget && instance.attributes.getNamedItem('maxLength')){
return (Number(instance.attributes.getNamedItem('maxlength')?.value) >= instance.validationTarget.value.length);
if(instance.validationTarget && instance.getAttribute('maxlength')){
return (Number(instance.getAttribute('maxlength')) >= instance.validationTarget.value.length);
}
return true;
}
};

export const textAreaValidators = [
...innerInputValidators,
textareaLengthValidator,
requiredValidator
...innerInputValidators,
textareaLengthValidator
]

0 comments on commit 51e2725

Please sign in to comment.