From 4c101b9ab13a7e52de255eb9705edc7d70d70d4c Mon Sep 17 00:00:00 2001 From: John Kreitlow <863023+radium-v@users.noreply.github.com> Date: Fri, 9 Dec 2022 13:41:10 -0800 Subject: [PATCH 1/5] add open-wc form-control to fast-foundation --- packages/web-components/fast-foundation/package.json | 1 + yarn.lock | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/packages/web-components/fast-foundation/package.json b/packages/web-components/fast-foundation/package.json index 80648487ee9..d67f1b0bdad 100644 --- a/packages/web-components/fast-foundation/package.json +++ b/packages/web-components/fast-foundation/package.json @@ -97,6 +97,7 @@ "dependencies": { "@floating-ui/dom": "^1.0.3", "@microsoft/fast-element": "2.0.0-beta.23", + "@open-wc/form-control": "^0.4.1", "@microsoft/fast-web-utilities": "^6.0.0", "tabbable": "^5.2.0", "tslib": "^2.4.0" diff --git a/yarn.lock b/yarn.lock index 86fa66a3d8b..c0a8a17ccbc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3845,6 +3845,11 @@ dependencies: "@octokit/openapi-types" "^13.11.0" +"@open-wc/form-control@^0.4.1": + version "0.4.1" + resolved "https://registry.yarnpkg.com/@open-wc/form-control/-/form-control-0.4.1.tgz#8ad8bd9f83d7619b2d8f71d26ba919f8061b6142" + integrity sha512-9mUrlKgB9No56LtcOeG9sTy16r9aQsOR/9fKh3r9xtkAgaU6tK9nlI8u9z/6CHsvMeyumxuWjE5sypajVN7qBA== + "@parcel/watcher@2.0.4": version "2.0.4" resolved "https://registry.yarnpkg.com/@parcel/watcher/-/watcher-2.0.4.tgz#f300fef4cc38008ff4b8c29d92588eced3ce014b" From 21505ca48b5d80e22b0f328b7c57a42456f8bcca Mon Sep 17 00:00:00 2001 From: John Kreitlow <863023+radium-v@users.noreply.github.com> Date: Tue, 17 Jan 2023 12:24:44 -0800 Subject: [PATCH 2/5] work in progress --- .../fast-foundation/docs/api-report.md | 51 +++- .../fast-foundation/package.json | 1 + .../fast-foundation/src/checkbox/README.md | 61 ++++- .../src/checkbox/checkbox.template.ts | 6 +- .../fast-foundation/src/checkbox/checkbox.ts | 242 ++++++++++++++++-- .../src/checkbox/stories/checkbox.register.ts | 2 - .../src/checkbox/stories/checkbox.stories.ts | 6 +- yarn.lock | 5 + 8 files changed, 324 insertions(+), 50 deletions(-) diff --git a/packages/web-components/fast-foundation/docs/api-report.md b/packages/web-components/fast-foundation/docs/api-report.md index 1b30ff3053d..956b79c7152 100644 --- a/packages/web-components/fast-foundation/docs/api-report.md +++ b/packages/web-components/fast-foundation/docs/api-report.md @@ -6,6 +6,7 @@ import { CaptureType } from '@microsoft/fast-element'; import { Constructable } from '@microsoft/fast-element'; +import { Constructor } from '@open-wc/form-control'; import { CSSDirective } from '@microsoft/fast-element'; import { Direction } from '@microsoft/fast-web-utilities'; import type { ElementsFilter } from '@microsoft/fast-element'; @@ -13,11 +14,14 @@ import { ElementStyles } from '@microsoft/fast-element'; import { ElementViewTemplate } from '@microsoft/fast-element'; import { FASTElement } from '@microsoft/fast-element'; import { FASTElementDefinition } from '@microsoft/fast-element'; +import { FormControlInterface } from '@open-wc/form-control'; import { HostBehavior } from '@microsoft/fast-element'; import { HostController } from '@microsoft/fast-element'; import { HTMLDirective } from '@microsoft/fast-element'; import { Orientation } from '@microsoft/fast-web-utilities'; +import { PartialFASTElementDefinition } from '@microsoft/fast-element'; import type { SyntheticViewTemplate } from '@microsoft/fast-element'; +import { Validator } from '@open-wc/form-control'; import { ViewTemplate } from '@microsoft/fast-element'; // @public @@ -911,20 +915,53 @@ export interface FASTCalendar extends StartEnd { export class FASTCard extends FASTElement { } -// Warning: (ae-forgotten-export) The symbol "FormAssociatedCheckbox" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "FASTCheckbox_base" needs to be exported by the entry point index.d.ts // // @public -export class FASTCheckbox extends FormAssociatedCheckbox { - constructor(); - // @internal (undocumented) - clickHandler: (e: MouseEvent) => void; +export class FASTCheckbox extends FASTCheckbox_base { + // (undocumented) + ariaChecked: string | null; + // (undocumented) + checked: boolean; + checkedAttribute: boolean; + // (undocumented) + protected checkedAttributeChanged(prev: boolean | undefined, next: boolean): void; + // (undocumented) + checkedChanged(prev: boolean | undefined, next: boolean): void; + // @internal + clickHandler: (e: Event) => void; + currentChecked: boolean; + // (undocumented) + currentCheckedChanged(prev: boolean | undefined, next: boolean): void; + // (undocumented) + defaultChecked: boolean; + // (undocumented) + defaultCheckedChanged(): void; // @internal (undocumented) defaultSlottedNodes: Node[]; - indeterminate: boolean; + protected dirtyChecked: boolean; // @internal + dirtyValue: boolean; + disabled: boolean; + // (undocumented) + static formControlValidators: Validator[]; + indeterminate: boolean | undefined; + // (undocumented) + indeterminateChanged(prev: boolean | undefined, next: boolean | undefined): void; initialValue: string; - // @internal (undocumented) + initialValueChanged(previous: string, next: string): void; + // @internal keypressHandler: (e: KeyboardEvent) => void; + name: string; + required: boolean; + // (undocumented) + resetFormControl(): void; + // (undocumented) + shouldFormValueUpdate(): boolean; + // (undocumented) + value: string; + // (undocumented) + valueChanged(previous: string, next: string): void; } // Warning: (ae-different-release-tags) This symbol has another declaration with a different release tag diff --git a/packages/web-components/fast-foundation/package.json b/packages/web-components/fast-foundation/package.json index d67f1b0bdad..c105d35db88 100644 --- a/packages/web-components/fast-foundation/package.json +++ b/packages/web-components/fast-foundation/package.json @@ -75,6 +75,7 @@ "@storybook/html": "6.5.10", "@storybook/manager-webpack5": "6.5.10", "concurrently": "^7.3.0", + "element-internals-polyfill": "^1.1.17", "esm": "^3.2.25", "express": "^4.18.1", "expect": "29.2.1", diff --git a/packages/web-components/fast-foundation/src/checkbox/README.md b/packages/web-components/fast-foundation/src/checkbox/README.md index 36c6d7d9ade..3e66a014106 100644 --- a/packages/web-components/fast-foundation/src/checkbox/README.md +++ b/packages/web-components/fast-foundation/src/checkbox/README.md @@ -104,16 +104,52 @@ export const myCheckbox = Checkbox.compose({ #### Superclass -| Name | Module | Package | -| ------------------------ | ----------------------------------------- | ------- | -| `FormAssociatedCheckbox` | /src/checkbox/checkbox.form-associated.js | | +| Name | Module | Package | +| ------------- | ------ | ----------------------- | +| `FASTElement` | | @microsoft/fast-element | + +#### Mixins + +| Name | Module | Package | +| ------------------ | ------ | --------------------- | +| `FormControlMixin` | | @open-wc/form-control | + +#### Static Fields + +| Name | Privacy | Type | Default | Description | Inherited From | +| ----------------------- | ------- | ------- | --------------------- | ----------- | -------------- | +| `formControlValidators` | | `array` | `[requiredValidator]` | | | #### Fields -| Name | Privacy | Type | Default | Description | Inherited From | -| --------------- | ------- | --------- | ------- | -------------------------------------- | ---------------------- | -| `indeterminate` | public | `boolean` | `false` | The indeterminate state of the control | | -| `proxy` | | | | | FormAssociatedCheckbox | +| Name | Privacy | Type | Default | Description | Inherited From | +| ------------------ | --------- | ---------------------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------- | +| `checkedAttribute` | public | `boolean` | `false` | The initial state of the checkbox. | | +| `defaultChecked` | public | `boolean` | | | | +| `initialValue` | public | `string` | `"on"` | The initial value of the form. This value sets the \`value\` property only when the \`value\` property has not been explicitly set. | | +| `value` | public | `string` | | | | +| `currentChecked` | public | `boolean` | | The current checkedness of the element. This property serves as a mechanism to set the \`checked\` property through both property assignment and the .setAttribute() method. This is useful for setting the field's checkedness in UI libraries that bind data through the .setAttribute() API and don't support IDL attribute binding. | | +| `dirtyChecked` | protected | `boolean` | `false` | Tracks whether the "checked" property has been changed. This is necessary to provide consistent behavior with normal input checkboxes | | +| `checked` | public | `boolean` | `false` | | | +| `disabled` | public | `boolean` | `false` | Sets the element's disabled state. A disabled element will not be included during form submission. | | +| `ariaChecked` | public | `string or null` | | | | +| `indeterminate` | public | `boolean or undefined` | | The indeterminate state of the control | | +| `name` | public | `string` | | The name of the element. This element's value will be surfaced during form submission under the provided name. | | +| `required` | public | `boolean` | `false` | The required state of the element. If true, the element will be required to complete the form. | | + +#### Methods + +| Name | Privacy | Description | Parameters | Return | Inherited From | +| ------------------------- | --------- | --------------------------------------------------- | -------------------------------------------------------- | --------- | -------------- | +| `checkedAttributeChanged` | protected | | `prev: boolean or undefined, next: boolean` | `void` | | +| `defaultCheckedChanged` | public | | | `void` | | +| `initialValueChanged` | public | Invoked when the \`initialValue\` property changes. | `previous: string, next: string` | `void` | | +| `valueChanged` | public | | `previous: string, next: string` | `void` | | +| `currentCheckedChanged` | public | | `prev: boolean or undefined, next: boolean` | | | +| `checkedChanged` | public | | `prev: boolean or undefined, next: boolean` | `void` | | +| `shouldFormValueUpdate` | | | | `boolean` | | +| `resetFormControl` | | | | `void` | | +| `indeterminateChanged` | public | | `prev: boolean or undefined, next: boolean or undefined` | `void` | | #### Events @@ -121,6 +157,17 @@ export const myCheckbox = Checkbox.compose({ | -------- | ---- | ---------------------------------------------------------- | -------------- | | `change` | | Emits a custom change event when the checked state changes | | +#### Attributes + +| Name | Field | Inherited From | +| ----------------- | ---------------- | -------------- | +| `checked` | checkedAttribute | | +| `value` | initialValue | | +| `current-checked` | currentChecked | | +| | disabled | | +| `name` | name | | +| | required | | + #### CSS Parts | Name | Description | diff --git a/packages/web-components/fast-foundation/src/checkbox/checkbox.template.ts b/packages/web-components/fast-foundation/src/checkbox/checkbox.template.ts index 9e6975ddb62..555c7783475 100644 --- a/packages/web-components/fast-foundation/src/checkbox/checkbox.template.ts +++ b/packages/web-components/fast-foundation/src/checkbox/checkbox.template.ts @@ -12,12 +12,12 @@ export function checkboxTemplate( return html`