Skip to content

Commit

Permalink
fix: add hidden property to polymer based components (#171) (#176)
Browse files Browse the repository at this point in the history
Co-authored-by: Tomi Virkki <tomivirkki@users.noreply.github.com>
  • Loading branch information
vaadin-bot and tomivirkki authored Dec 15, 2023
1 parent a6d7543 commit 34f431d
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/utils/createComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function createComponent<I extends HTMLElement, E extends EventNames = {}
elementClass: {
// @ts-expect-error: it is a specific workaround for Polymer classes.
name: elementClass.name,
prototype: elementClass._properties,
prototype: { ...elementClass._properties, hidden: Boolean },
},
}
: options,
Expand Down
27 changes: 26 additions & 1 deletion test/Select.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import chaiDom from 'chai-dom';
import type { ReactElement } from 'react';
import { ListBox } from '../src/ListBox.js';
import { Item } from '../src/Item.js';
import { Select } from '../src/Select.js';
import { Select, SelectElement } from '../src/Select.js';
import { findByQuerySelector } from './utils/findByQuerySelector.js';

useChaiPlugin(chaiDom);
Expand Down Expand Up @@ -143,4 +143,29 @@ describe('Select', () => {
await expect(findByQuerySelector('div[slot="prefix"]')).to.eventually.have.text('Value:');
});
});

describe('boolean property', () => {
const booleanProperties: Array<keyof typeof SelectElement.prototype & string> = [
'disabled',
'hidden',
'opened',
'draggable',
];

booleanProperties.forEach((property) => {
describe(property, () => {
it(`should be true in the element if ${property} prop is true`, async () => {
render(<Select items={[{ label: 'foo', value: 'foo' }]} {...{ [property]: true }} />);
const select = await findByQuerySelector('vaadin-select');
expect(select[property]).to.be.ok;
});

it(`should be false in the element if ${property} prop is false`, async () => {
render(<Select items={[{ label: 'foo', value: 'foo' }]} {...{ [property]: false }} />);
const select = await findByQuerySelector('vaadin-select');
expect(select[property]).not.to.be.ok;
});
});
});
});
});
33 changes: 33 additions & 0 deletions test/SideNav.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { expect, use as useChaiPlugin } from '@esm-bundle/chai';
import { render } from '@testing-library/react';
import chaiDom from 'chai-dom';
import { SideNav, SideNavElement } from '../src/SideNav.js';
import { findByQuerySelector } from './utils/findByQuerySelector.js';

useChaiPlugin(chaiDom);

describe('SideNav', () => {
describe('boolean property', () => {
const booleanProperties: Array<keyof typeof SideNavElement.prototype & string> = [
'hidden',
'collapsed',
'draggable',
];

booleanProperties.forEach((property) => {
describe(property, () => {
it(`should be true in the element if ${property} prop is true`, async () => {
render(<SideNav {...{ [property]: true }} />);
const sideNav = await findByQuerySelector('vaadin-side-nav');
expect(sideNav[property]).to.be.ok;
});

it(`should be false in the element if ${property} prop is false`, async () => {
render(<SideNav {...{ [property]: false }} />);
const sideNav = await findByQuerySelector('vaadin-side-nav');
expect(sideNav[property]).not.to.be.ok;
});
});
});
});
});

0 comments on commit 34f431d

Please sign in to comment.