Skip to content

fix: rename 'unselect' event to 'deselect' #497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/uui-base/lib/events/UUISelectableEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { UUIEvent } from './UUIEvent';

export class UUISelectableEvent extends UUIEvent<{}, SelectableMixinInterface> {
public static readonly SELECTED = 'selected';
public static readonly UNSELECTED = 'unselected';
public static readonly DESELECTED = 'deselected';

constructor(evName: string, eventInit: any | null = {}) {
super(evName, {
Expand Down
16 changes: 8 additions & 8 deletions packages/uui-base/lib/mixins/SelectableMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type Constructor<T = {}> = new (...args: any[]) => T;

export declare class SelectableMixinInterface extends LitElement {
selectable: boolean;
unselectable: boolean;
deselectable: boolean;
selected: boolean;
selectableTarget: EventTarget;
}
Expand All @@ -24,7 +24,7 @@ export const SelectableMixin = <T extends Constructor<LitElement>>(
) => {
/**
* @fires {UUISelectableEvent} selected - fires when the media card is selected
* @fires {UUISelectableEvent} unselected - fires when the media card is unselected
* @fires {UUISelectableEvent} deselected - fires when the media card is deselected
*/
class SelectableMixinClass extends superClass {
private _selectable = false;
Expand All @@ -45,7 +45,7 @@ export const SelectableMixin = <T extends Constructor<LitElement>>(
this.requestUpdate('selected', oldVal);
}

protected unselectable = true;
protected deselectable = true;

/**
* Attribute applied when the element is selected.
Expand Down Expand Up @@ -79,9 +79,9 @@ export const SelectableMixin = <T extends Constructor<LitElement>>(
this.selected = true;
}

private _unselect() {
if (!this.unselectable) return;
const selectEvent = new UUISelectableEvent(UUISelectableEvent.UNSELECTED);
private _deselect() {
if (!this.deselectable) return;
const selectEvent = new UUISelectableEvent(UUISelectableEvent.DESELECTED);
this.dispatchEvent(selectEvent);
if (selectEvent.defaultPrevented) return;

Expand All @@ -95,10 +95,10 @@ export const SelectableMixin = <T extends Constructor<LitElement>>(
}

private _toggleSelect() {
if (this.unselectable === false) {
if (this.deselectable === false) {
this._select();
} else {
this.selected ? this._unselect() : this._select();
this.selected ? this._deselect() : this._select();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,16 @@ describe('UUICardContentNodeElement', () => {
});
});

describe('unselect', () => {
it('emits a unselected event when preselected', async () => {
describe('deselect', () => {
it('emits a deselected event when preselected', async () => {
element.selectable = true;
element.selected = true;
await elementUpdated(element);
const listener = oneEvent(element, UUISelectableEvent.UNSELECTED);
const listener = oneEvent(element, UUISelectableEvent.DESELECTED);
element.click();
const event = await listener;
expect(event).to.exist;
expect(event.type).to.equal(UUISelectableEvent.UNSELECTED);
expect(event.type).to.equal(UUISelectableEvent.DESELECTED);
expect(element.selected).to.be.false;
});
});
Expand Down
8 changes: 4 additions & 4 deletions packages/uui-card-media/lib/uui-card-media.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,16 @@ describe('UUICardMediaElement', () => {
});
});

describe('unselect', () => {
it('emits a unselected event when preselected', async () => {
describe('deselect', () => {
it('emits a deselected event when preselected', async () => {
element.selectable = true;
element.selected = true;
await elementUpdated(element);
const listener = oneEvent(element, UUISelectableEvent.UNSELECTED);
const listener = oneEvent(element, UUISelectableEvent.DESELECTED);
element.click();
const event = await listener;
expect(event).to.exist;
expect(event.type).to.equal(UUISelectableEvent.UNSELECTED);
expect(event.type).to.equal(UUISelectableEvent.DESELECTED);
expect(element.selected).to.be.false;
});
});
Expand Down
8 changes: 4 additions & 4 deletions packages/uui-card-user/lib/uui-card-user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,16 @@ describe('UUICardUserElement', () => {
});
});

describe('unselect', () => {
it('emits a unselected event when preselected', async () => {
describe('deselect', () => {
it('emits a deselected event when preselected', async () => {
element.selectable = true;
element.selected = true;
await elementUpdated(element);
const listener = oneEvent(element, UUISelectableEvent.UNSELECTED);
const listener = oneEvent(element, UUISelectableEvent.DESELECTED);
element.click();
const event = await listener;
expect(event).to.exist;
expect(event.type).to.equal(UUISelectableEvent.UNSELECTED);
expect(event.type).to.equal(UUISelectableEvent.DESELECTED);
expect(element.selected).to.be.false;
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/uui-color-swatch/lib/uui-color-swatch.element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ export class UUIColorSwatchElement extends LabelMixin(
if (changedProperties.has('disabled')) {
if (this.selectable) {
this.selectable = !this.disabled;
this.unselectable = !this.disabled;
this.deselectable = !this.disabled;
}
}
if (
Expand Down
4 changes: 2 additions & 2 deletions packages/uui-color-swatches/lib/uui-color-swatches.element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class UUIColorSwatchesElement extends LabelMixin('label', LitElement) {
constructor() {
super();
this.addEventListener(UUISelectableEvent.SELECTED, this._onSelected);
this.addEventListener(UUISelectableEvent.UNSELECTED, this._onUnselected);
this.addEventListener(UUISelectableEvent.DESELECTED, this._onDeselected);
}

connectedCallback() {
Expand Down Expand Up @@ -112,7 +112,7 @@ export class UUIColorSwatchesElement extends LabelMixin('label', LitElement) {
this.dispatchEvent(new UUIColorSwatchesEvent(UUIColorSwatchesEvent.CHANGE));
};

private _onUnselected = (event: Event) => {
private _onDeselected = (event: Event) => {
const target = event.target as UUIColorSwatchElement;
if (!this.swatches.includes(target)) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class UUIComboboxListOptionElement extends SelectableMixin(
constructor() {
super();
this.selectable = true;
this.unselectable = false;
this.deselectable = false;
}

render() {
Expand Down
6 changes: 3 additions & 3 deletions packages/uui-combobox-list/lib/uui-combobox-list.element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ export class UUIComboboxListElement extends LitElement {
}

this.addEventListener(UUISelectableEvent.SELECTED, this._onSelected);
this.addEventListener(UUISelectableEvent.UNSELECTED, this._onUnselected);
this.addEventListener(UUISelectableEvent.DESELECTED, this._onDeselected);
}

disconnectedCallback(): void {
super.disconnectedCallback();
document.removeEventListener('keydown', this._onKeyDown);

this.removeEventListener(UUISelectableEvent.SELECTED, this._onSelected);
this.removeEventListener(UUISelectableEvent.UNSELECTED, this._onUnselected);
this.removeEventListener(UUISelectableEvent.DESELECTED, this._onDeselected);
}

private _updateSelection() {
Expand Down Expand Up @@ -169,7 +169,7 @@ export class UUIComboboxListElement extends LitElement {

this.dispatchEvent(new UUIComboboxListEvent(UUIComboboxListEvent.CHANGE));
};
private _onUnselected = (e: Event) => {
private _onDeselected = (e: Event) => {
const el = e.composedPath()[0] as UUIComboboxListOptionElement;
if (this._activeElement === el) {
this._activeElement = undefined;
Expand Down
10 changes: 5 additions & 5 deletions packages/uui-menu-item/lib/uui-menu-item.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,22 @@ describe('UUIMenuItemElement', () => {
});
});

describe('unselect', async () => {
it('emits a cancelable unselected event when preselected', async () => {
describe('deselect', async () => {
it('emits a cancelable deselected event when preselected', async () => {
element.selectable = true;
element.selected = true;
await elementUpdated(element);
const labelElement = element.shadowRoot!.querySelector(
'#label-button'
) as HTMLElement;
element.addEventListener(UUISelectableEvent.UNSELECTED, e => {
element.addEventListener(UUISelectableEvent.DESELECTED, e => {
e.preventDefault();
});
const listener = oneEvent(element, UUISelectableEvent.UNSELECTED);
const listener = oneEvent(element, UUISelectableEvent.DESELECTED);
labelElement.click();
const event = await listener;
expect(event).to.exist;
expect(event.type).to.equal(UUISelectableEvent.UNSELECTED);
expect(event.type).to.equal(UUISelectableEvent.DESELECTED);
expect(element.selected).to.be.true;
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { property } from 'lit/decorators.js';
* @element uui-ref-node-data-type
* @fires {UUIRefEvent} open - fires when the ref title is clicked
* @fires {UUIRefEvent} selected - fires when the ref is selected
* @fires {UUIRefEvent} unselected - fires when the ref is unselected
* @fires {UUIRefEvent} deselected - fires when the ref is deselected
* @description - Component for displaying a reference to a Data Type node.
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { property } from 'lit/decorators.js';
* @element uui-ref-node-document-type
* @fires {UUIRefEvent} open - fires when the ref title is clicked
* @fires {UUIRefEvent} selected - fires when the ref is selected
* @fires {UUIRefEvent} unselected - fires when the ref is unselected
* @fires {UUIRefEvent} deselected - fires when the ref is deselected
* @description - Component for displaying a reference to a Content type(Document Type, Media Type, Element Type etc.) node.
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
* @element uui-ref-node-form
* @fires {UUIRefEvent} open - fires when the ref title is clicked
* @fires {UUIRefEvent} selected - fires when the ref is selected
* @fires {UUIRefEvent} unselected - fires when the ref is unselected
* @fires {UUIRefEvent} deselected - fires when the ref is deselected
* @description - Component for displaying a reference to a form node.
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { property } from 'lit/decorators.js';
* @element uui-ref-node-member
* @fires {UUIRefEvent} open - fires when the ref title is clicked
* @fires {UUIRefEvent} selected - fires when the ref is selected
* @fires {UUIRefEvent} unselected - fires when the ref is unselected
* @fires {UUIRefEvent} deselected - fires when the ref is deselected
* @description - Component for displaying a reference to a Member node.
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { property } from 'lit/decorators.js';
* @element uui-ref-node-package
* @fires {UUIRefEvent} open - fires when the ref title is clicked
* @fires {UUIRefEvent} selected - fires when the ref is selected
* @fires {UUIRefEvent} unselected - fires when the ref is unselected
* @fires {UUIRefEvent} deselected - fires when the ref is deselected
* @description - Component for displaying a reference to a Package node.
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { property } from 'lit/decorators.js';
* @element uui-ref-node-user
* @fires {UUIRefEvent} open - fires when the ref title is clicked
* @fires {UUIRefEvent} selected - fires when the ref is selected
* @fires {UUIRefEvent} unselected - fires when the ref is unselected
* @fires {UUIRefEvent} deselected - fires when the ref is deselected
* @description - Component for displaying a reference to a user node.
*/

Expand Down
2 changes: 1 addition & 1 deletion packages/uui-ref-node/lib/uui-ref-node.element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { property, state } from 'lit/decorators.js';
* @element uui-ref-node
* @fires {UUIRefEvent} open - fires when the ref title is clicked
* @fires {UUIRefEvent} selected - fires when the ref is selected
* @fires {UUIRefEvent} unselected - fires when the ref is unselected
* @fires {UUIRefEvent} deselected - fires when the ref is deselected
* @description - Component for displaying a reference to a generic node.
* @slot - for content
* @slot icon - for an icon
Expand Down
2 changes: 1 addition & 1 deletion packages/uui-ref/lib/uui-ref.element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { UUIRefEvent } from './UUIRefEvent';
* @element uui-ref
* @fires {UUIRefEvent} open - fires when the ref is opened
* @fires {UUISelectableEvent} selected - fires when the ref is selected
* @fires {UUISelectableEvent} unselected - fires when the ref is unselected
* @fires {UUISelectableEvent} deselected - fires when the ref is deselected
* @description - Base ref component to be extended by specific ref elements. Does not have a tag.
*/

Expand Down
4 changes: 2 additions & 2 deletions packages/uui-table/lib/uui-table-advanced-example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class UUITableWithSelectionExampleElement extends LitElement {
this._selection = [...this._selection, item.key];
this._selectionMode = this._selection.length > 0;
}
private _unselectRowHandler(item: TableItem) {
private _deselectRowHandler(item: TableItem) {
this._selection = this._selection.filter(
selectionKey => selectionKey !== item.key
);
Expand Down Expand Up @@ -237,7 +237,7 @@ export class UUITableWithSelectionExampleElement extends LitElement {
?select-only=${this._selectionMode}
?selected=${this._isSelected(item.key)}
@selected=${() => this._selectRowHandler(item)}
@unselected=${() => this._unselectRowHandler(item)}>
@deselected=${() => this._deselectRowHandler(item)}>
<uui-table-cell>
<uui-icon name="wand" style="font-size: 20px;"></uui-icon>
<uui-checkbox
Expand Down