Merge pull request #955 from ing-bank/feat/choice-types

feat: add types for checkbox-group & radio-group
This commit is contained in:
Joren Broekema 2020-09-28 11:53:40 +02:00 committed by GitHub
commit 9a74bfdc6e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 49 additions and 20 deletions

View file

@ -0,0 +1,5 @@
---
'@lion/radio-group': minor
---
Added types for the radio-group package.

View file

@ -0,0 +1,5 @@
---
'@lion/checkbox-group': minor
---
Added types for checkbox-group package.

View file

@ -1,6 +1,12 @@
module.exports = { module.exports = {
extends: ['@open-wc/eslint-config', 'eslint-config-prettier'].map(require.resolve), extends: ['@open-wc/eslint-config', 'eslint-config-prettier'].map(require.resolve),
overrides: [ overrides: [
{
files: ['**/*.js'],
rules: {
'wc/guard-super-call': 'off', // types will prevent you from calling the super if it's not in the base class, making the guard unnecessary
},
},
{ {
files: [ files: [
'**/test-suites/**/*.js', '**/test-suites/**/*.js',

View file

@ -3,7 +3,7 @@ import { ChoiceInputMixin } from '@lion/form-core';
export class LionCheckbox extends ChoiceInputMixin(LionInput) { export class LionCheckbox extends ChoiceInputMixin(LionInput) {
connectedCallback() { connectedCallback() {
if (super.connectedCallback) super.connectedCallback(); super.connectedCallback();
this.type = 'checkbox'; this.type = 'checkbox';
} }
} }

View file

@ -3,15 +3,15 @@ import { ChoiceGroupMixin, FormGroupMixin } from '@lion/form-core';
/** /**
* A wrapper around multiple checkboxes * A wrapper around multiple checkboxes
*
* @extends {LionFieldset}
*/ */
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/40110
export class LionCheckboxGroup extends ChoiceGroupMixin(FormGroupMixin(LitElement)) { export class LionCheckboxGroup extends ChoiceGroupMixin(FormGroupMixin(LitElement)) {
constructor() { constructor() {
super(); super();
this.multipleChoice = true; this.multipleChoice = true;
} }
/** @param {import('lit-element').PropertyValues } changedProperties */
updated(changedProperties) { updated(changedProperties) {
super.updated(changedProperties); super.updated(changedProperties);
if (changedProperties.has('name') && !String(this.name).match(/\[\]$/)) { if (changedProperties.has('name') && !String(this.name).match(/\[\]$/)) {

View file

@ -1,8 +1,15 @@
import { localizeTearDown } from '@lion/localize/test-helpers.js'; import { localizeTearDown } from '@lion/localize/test-helpers.js';
import { expect, fixture, html } from '@open-wc/testing'; import { expect, fixture as _fixture, html } from '@open-wc/testing';
import '../lion-checkbox-group.js'; import '../lion-checkbox-group.js';
import '../lion-checkbox.js'; import '../lion-checkbox.js';
/**
* @typedef {import('../src/LionCheckboxGroup').LionCheckboxGroup} LionCheckboxGroup
* @typedef {import('lit-html').TemplateResult} TemplateResult
*/
const fixture = /** @type {(arg: TemplateResult) => Promise<LionCheckboxGroup>} */ (_fixture);
beforeEach(() => { beforeEach(() => {
localizeTearDown(); localizeTearDown();
}); });

View file

@ -19,11 +19,10 @@ import { LionInput } from '@lion/input';
* <lion-radio checked> * <lion-radio checked>
* *
* @customElement lion-radio * @customElement lion-radio
* @extends {LionInput}
*/ */
export class LionRadio extends ChoiceInputMixin(LionInput) { export class LionRadio extends ChoiceInputMixin(LionInput) {
connectedCallback() { connectedCallback() {
if (super.connectedCallback) super.connectedCallback(); super.connectedCallback();
this.type = 'radio'; this.type = 'radio';
} }
} }

View file

@ -3,12 +3,10 @@ import { ChoiceGroupMixin, FormGroupMixin } from '@lion/form-core';
/** /**
* A wrapper around multiple radios. * A wrapper around multiple radios.
*
* @extends {LionFieldset}
*/ */
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/40110
export class LionRadioGroup extends ChoiceGroupMixin(FormGroupMixin(LitElement)) { export class LionRadioGroup extends ChoiceGroupMixin(FormGroupMixin(LitElement)) {
connectedCallback() { connectedCallback() {
// eslint-disable-next-line wc/guard-super-call
super.connectedCallback(); super.connectedCallback();
this.setAttribute('role', 'radiogroup'); this.setAttribute('role', 'radiogroup');
} }

View file

@ -1,8 +1,15 @@
import { expect, fixture, html } from '@open-wc/testing'; import { expect, fixture as _fixture, html } from '@open-wc/testing';
import '../lion-radio-group.js'; import '../lion-radio-group.js';
import '../lion-radio.js'; import '../lion-radio.js';
/**
* @typedef {import('../src/LionRadioGroup').LionRadioGroup} LionRadioGroup
* @typedef {import('../src/LionRadio').LionRadio} LionRadio
* @typedef {import('lit-html').TemplateResult} TemplateResult
*/
const fixture = /** @type {(arg: TemplateResult) => Promise<LionRadioGroup>} */ (_fixture);
describe('<lion-radio-group>', () => { describe('<lion-radio-group>', () => {
it('should have role = radiogroup', async () => { it('should have role = radiogroup', async () => {
const el = await fixture(html` const el = await fixture(html`
@ -24,7 +31,7 @@ describe('<lion-radio-group>', () => {
el.children[1].focus(); el.children[1].focus();
expect(el.touched).to.equal(false, 'initially, touched state is false'); expect(el.touched).to.equal(false, 'initially, touched state is false');
el.children[1].checked = true; /** @type {LionRadio} */ (el.children[1]).checked = true;
expect(el.touched, `focused via a mouse click, group should be touched`).to.be.true; expect(el.touched, `focused via a mouse click, group should be touched`).to.be.true;
}); });

View file

@ -16,17 +16,19 @@
}, },
"include": [ "include": [
"packages/accordion/**/*.js", "packages/accordion/**/*.js",
"packages/core/**/*.js",
"packages/tabs/**/*.js",
"packages/singleton-manager/**/*.js",
"packages/localize/**/*.js",
"packages/form-core/**/*.js",
"packages/overlays/**/*.js",
"packages/tooltip/**/*.js",
"packages/button/src/**/*.js", "packages/button/src/**/*.js",
"packages/listbox/src/*.js", "packages/checkbox-group/**/*.js",
"packages/core/**/*.js",
"packages/form-core/**/*.js",
"packages/input/**/*.js", "packages/input/**/*.js",
"packages/input-amount/**/*.js" "packages/input-amount/**/*.js",
"packages/listbox/src/*.js",
"packages/localize/**/*.js",
"packages/overlays/**/*.js",
"packages/radio-group/**/*.js",
"packages/singleton-manager/**/*.js",
"packages/tabs/**/*.js",
"packages/tooltip/**/*.js"
], ],
"exclude": [ "exclude": [
"node_modules", "node_modules",