Skip to content

Commit

Permalink
Revert "feat: add dirty state to field components (#6160)"
Browse files Browse the repository at this point in the history
This reverts commit b123777.
  • Loading branch information
vursen committed Aug 31, 2023
1 parent f882c9c commit 201d019
Show file tree
Hide file tree
Showing 61 changed files with 6 additions and 1,056 deletions.
17 changes: 0 additions & 17 deletions packages/checkbox-group/src/vaadin-checkbox-group.d.ts
Expand Up @@ -14,11 +14,6 @@ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mix
*/
export type CheckboxGroupInvalidChangedEvent = CustomEvent<{ value: boolean }>;

/**
* Fired when the `dirty` property changes.
*/
export type CheckboxGroupDirtyChangedEvent = CustomEvent<{ value: boolean }>;

/**
* Fired when the `value` property changes.
*/
Expand All @@ -32,8 +27,6 @@ export type CheckboxGroupValidatedEvent = CustomEvent<{ valid: boolean }>;
export interface CheckboxGroupCustomEventMap {
'invalid-changed': CheckboxGroupInvalidChangedEvent;

'dirty-changed': CheckboxGroupDirtyChangedEvent;

'value-changed': CheckboxGroupValueChangedEvent;

validated: CheckboxGroupValidatedEvent;
Expand Down Expand Up @@ -80,7 +73,6 @@ export interface CheckboxGroupEventMap extends HTMLElementEventMap, CheckboxGrou
* See [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.
*
* @fires {CustomEvent} invalid-changed - Fired when the `invalid` property changes.
* @fires {CustomEvent} dirty-changed - Fired when the `dirty` property changes.
* @fires {CustomEvent} value-changed - Fired when the `value` property changes.
* @fires {CustomEvent} validated - Fired whenever the field is validated.
*/
Expand All @@ -93,15 +85,6 @@ declare class CheckboxGroup extends FieldMixin(FocusMixin(DisabledMixin(ElementM
*/
value: string[];

/**
* Whether the field is dirty.
*
* The field is automatically marked as dirty once the user triggers
* a `change` event. Additionally, the field can be manually marked
* as dirty by setting the property to `true`.
*/
dirty: boolean;

addEventListener<K extends keyof CheckboxGroupEventMap>(
type: K,
listener: (this: CheckboxGroup, ev: CheckboxGroupEventMap[K]) => void,
Expand Down
21 changes: 0 additions & 21 deletions packages/checkbox-group/src/vaadin-checkbox-group.js
Expand Up @@ -139,19 +139,6 @@ class CheckboxGroup extends FieldMixin(FocusMixin(DisabledMixin(ElementMixin(The
notify: true,
observer: '__valueChanged',
},

/**
* Whether the field is dirty.
*
* The field is automatically marked as dirty once the user triggers
* a `change` event. Additionally, the field can be manually marked
* as dirty by setting the property to `true`.
*/
dirty: {
type: Boolean,
value: false,
notify: true,
},
};
}

Expand All @@ -160,7 +147,6 @@ class CheckboxGroup extends FieldMixin(FocusMixin(DisabledMixin(ElementMixin(The

this.__registerCheckbox = this.__registerCheckbox.bind(this);
this.__unregisterCheckbox = this.__unregisterCheckbox.bind(this);
this.__onCheckboxChange = this.__onCheckboxChange.bind(this);
this.__onCheckboxCheckedChanged = this.__onCheckboxCheckedChanged.bind(this);
}

Expand Down Expand Up @@ -241,7 +227,6 @@ class CheckboxGroup extends FieldMixin(FocusMixin(DisabledMixin(ElementMixin(The
* @private
*/
__registerCheckbox(checkbox) {
checkbox.addEventListener('change', this.__onCheckboxChange);
checkbox.addEventListener('checked-changed', this.__onCheckboxCheckedChanged);

if (this.disabled) {
Expand All @@ -262,7 +247,6 @@ class CheckboxGroup extends FieldMixin(FocusMixin(DisabledMixin(ElementMixin(The
* @private
*/
__unregisterCheckbox(checkbox) {
checkbox.removeEventListener('change', this.__onCheckboxChange);
checkbox.removeEventListener('checked-changed', this.__onCheckboxCheckedChanged);

if (checkbox.checked) {
Expand Down Expand Up @@ -316,11 +300,6 @@ class CheckboxGroup extends FieldMixin(FocusMixin(DisabledMixin(ElementMixin(The
}
}

/** @private */
__onCheckboxChange() {
this.dirty = true;
}

/**
* @param {!CustomEvent} event
* @private
Expand Down
33 changes: 0 additions & 33 deletions packages/checkbox-group/test/checkbox-group.test.js
Expand Up @@ -302,39 +302,6 @@ describe('vaadin-checkbox-group', () => {
});
});

describe('dirty state', () => {
beforeEach(async () => {
group = fixtureSync(`
<vaadin-checkbox-group>
<vaadin-checkbox value="1" label="Checkbox 1"></vaadin-checkbox>
</vaadin-checkbox-group>
`);
await nextFrame();
checkboxes = [...group.querySelectorAll('vaadin-checkbox')];
});

it('should not be dirty by default', () => {
expect(group.dirty).to.be.false;
});

it('should not be dirty after programmatic value change', () => {
group.value = ['1'];
expect(group.dirty).to.be.false;
});

it('should be dirty after selecting a checkbox', () => {
checkboxes[0].click();
expect(group.dirty).to.be.true;
});

it('should fire dirty-changed event when the state changes', () => {
const spy = sinon.spy();
group.addEventListener('dirty-changed', spy);
group.dirty = true;
expect(spy.calledOnce).to.be.true;
});
});

describe('wrapping', () => {
beforeEach(async () => {
group = fixtureSync(`
Expand Down
6 changes: 0 additions & 6 deletions packages/checkbox-group/test/typings/checkbox-group.types.ts
@@ -1,6 +1,5 @@
import '../../vaadin-checkbox-group.js';
import type {
CheckboxGroupDirtyChangedEvent,
CheckboxGroupInvalidChangedEvent,
CheckboxGroupValidatedEvent,
CheckboxGroupValueChangedEvent,
Expand All @@ -15,11 +14,6 @@ group.addEventListener('invalid-changed', (event) => {
assertType<boolean>(event.detail.value);
});

group.addEventListener('dirty-changed', (event) => {
assertType<CheckboxGroupDirtyChangedEvent>(event);
assertType<boolean>(event.detail.value);
});

group.addEventListener('value-changed', (event) => {
assertType<CheckboxGroupValueChangedEvent>(event);
assertType<string[]>(event.detail.value);
Expand Down
12 changes: 0 additions & 12 deletions packages/checkbox/src/vaadin-checkbox-mixin.js
Expand Up @@ -103,18 +103,6 @@ export const CheckboxMixin = (superclass) =>
return super._shouldSetActive(event);
}

/**
* Override to mark the field as dirty on change.
*
* @param {Event} event
* @protected
* @override
*/
_onChange(event) {
this.dirty = true;
super._onChange(event);
}

/**
* Override method inherited from `CheckedMixin` to reset
* `indeterminate` state checkbox is toggled by the user.
Expand Down
8 changes: 0 additions & 8 deletions packages/checkbox/src/vaadin-checkbox.d.ts
Expand Up @@ -11,11 +11,6 @@ import { CheckedMixin } from '@vaadin/field-base/src/checked-mixin.js';
import { LabelMixin } from '@vaadin/field-base/src/label-mixin.js';
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';

/**
* Fired when the `dirty` property changes.
*/
export type CheckboxDirtyChangedEvent = CustomEvent<{ value: boolean }>;

/**
* Fired when the `checked` property changes.
*/
Expand All @@ -27,8 +22,6 @@ export type CheckboxCheckedChangedEvent = CustomEvent<{ value: boolean }>;
export type CheckboxIndeterminateChangedEvent = CustomEvent<{ value: boolean }>;

export interface CheckboxCustomEventMap {
'dirty-changed': CheckboxDirtyChangedEvent;

'checked-changed': CheckboxCheckedChangedEvent;

'indeterminate-changed': CheckboxIndeterminateChangedEvent;
Expand Down Expand Up @@ -65,7 +58,6 @@ export interface CheckboxEventMap extends HTMLElementEventMap, CheckboxCustomEve
*
* See [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.
*
* @fires {CustomEvent} dirty-changed - Fired when the `dirty` property changes.
* @fires {CustomEvent} checked-changed - Fired when the `checked` property changes.
* @fires {CustomEvent} indeterminate-changed - Fired when the `indeterminate` property changes.
*/
Expand Down
22 changes: 0 additions & 22 deletions packages/checkbox/test/checkbox.common.js
Expand Up @@ -236,26 +236,4 @@ describe('checkbox', () => {
expect(input.indeterminate).to.be.false;
});
});

describe('dirty state', () => {
beforeEach(async () => {
checkbox = fixtureSync(`<vaadin-checkbox></vaadin-checkbox>`);
await nextRender();
input = checkbox.inputElement;
});

it('should not be dirty by default', () => {
expect(checkbox.dirty).to.be.false;
});

it('should not be dirty after changing checked state programmatically', () => {
checkbox.checked = true;
expect(checkbox.dirty).to.be.false;
});

it('should be dirty after click', () => {
input.click();
expect(checkbox.dirty).to.be.true;
});
});
});
8 changes: 0 additions & 8 deletions packages/combo-box/src/vaadin-combo-box-light.d.ts
Expand Up @@ -41,11 +41,6 @@ export type ComboBoxLightOpenedChangedEvent = CustomEvent<{ value: boolean }>;
*/
export type ComboBoxLightInvalidChangedEvent = CustomEvent<{ value: boolean }>;

/**
* Fired when the `dirty` property changes.
*/
export type ComboBoxLightDirtyChangedEvent = CustomEvent<{ value: boolean }>;

/**
* Fired when the `value` property changes.
*/
Expand Down Expand Up @@ -77,8 +72,6 @@ export interface ComboBoxLightEventMap<TItem> extends HTMLElementEventMap {

'invalid-changed': ComboBoxLightInvalidChangedEvent;

'dirty-changed': ComboBoxLightDirtyChangedEvent;

'value-changed': ComboBoxLightValueChangedEvent;

'selected-item-changed': ComboBoxLightSelectedItemChangedEvent<TItem>;
Expand Down Expand Up @@ -129,7 +122,6 @@ export interface ComboBoxLightEventMap<TItem> extends HTMLElementEventMap {
* @fires {CustomEvent} invalid-changed - Fired when the `invalid` property changes.
* @fires {CustomEvent} opened-changed - Fired when the `opened` property changes.
* @fires {CustomEvent} selected-item-changed - Fired when the `selectedItem` property changes.
* @fires {CustomEvent} dirty-changed - Fired when the `dirty` property changes.
* @fires {CustomEvent} value-changed - Fired when the `value` property changes.
* @fires {CustomEvent} validated - Fired whenever the field is validated.
*/
Expand Down
7 changes: 1 addition & 6 deletions packages/combo-box/src/vaadin-combo-box-mixin.js
Expand Up @@ -1087,18 +1087,13 @@ export const ComboBoxMixin = (subclass) =>

/** @private */
_detectAndDispatchChange() {
const isValueChanged = this.value !== this._lastCommittedValue;
if (isValueChanged) {
this.dirty = true;
}

// Do not validate when focusout is caused by document
// losing focus, which happens on browser tab switch.
if (document.hasFocus()) {
this.validate();
}

if (isValueChanged) {
if (this.value !== this._lastCommittedValue) {
this.dispatchEvent(new CustomEvent('change', { bubbles: true }));
this._lastCommittedValue = this.value;
}
Expand Down
8 changes: 0 additions & 8 deletions packages/combo-box/src/vaadin-combo-box.d.ts
Expand Up @@ -53,11 +53,6 @@ export type ComboBoxOpenedChangedEvent = CustomEvent<{ value: boolean }>;
*/
export type ComboBoxInvalidChangedEvent = CustomEvent<{ value: boolean }>;

/**
* Fired when the `dirty` property changes.
*/
export type ComboBoxDirtyChangedEvent = CustomEvent<{ value: boolean }>;

/**
* Fired when the `value` property changes.
*/
Expand Down Expand Up @@ -89,8 +84,6 @@ export interface ComboBoxEventMap<TItem> extends HTMLElementEventMap {

'invalid-changed': ComboBoxInvalidChangedEvent;

'dirty-changed': ComboBoxDirtyChangedEvent;

'value-changed': ComboBoxValueChangedEvent;

'selected-item-changed': ComboBoxSelectedItemChangedEvent<TItem>;
Expand Down Expand Up @@ -219,7 +212,6 @@ export interface ComboBoxEventMap<TItem> extends HTMLElementEventMap {
* @fires {CustomEvent} filter-changed - Fired when the `filter` property changes.
* @fires {CustomEvent} invalid-changed - Fired when the `invalid` property changes.
* @fires {CustomEvent} opened-changed - Fired when the `opened` property changes.
* @fires {CustomEvent} dirty-changed - Fired when the `dirty` property changes.
* @fires {CustomEvent} selected-item-changed - Fired when the `selectedItem` property changes.
* @fires {CustomEvent} value-changed - Fired when the `value` property changes.
* @fires {CustomEvent} validated - Fired whenever the field is validated.
Expand Down
79 changes: 0 additions & 79 deletions packages/combo-box/test/dirty-state.test.js

This file was deleted.

0 comments on commit 201d019

Please sign in to comment.