Skip to content

Commit

Permalink
refactor(switch)!: Remove deprecated property and event payload. (#5921)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Removed deprecated `switched` property and
`calciteSwitchChange` event payload.

- Removed the property `switched`, use `checked` instead.
- Removed the `event.detail` from `calciteSwitchChange`, use
`event.target.checked` instead.
  • Loading branch information
driskull authored Dec 8, 2022
1 parent f1c7c6a commit 4ace1d3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 38 deletions.
11 changes: 0 additions & 11 deletions src/components/switch/switch.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,6 @@ describe("calcite-switch", () => {
expect(await calciteSwitch.getProperty("checked")).toBe(false);
});

it("can be checked via the switched property (deprecated)", async () => {
const page = await newE2EPage();
await page.setContent("<calcite-switch switched></calcite-switch>");

const calciteSwitch = await page.find("calcite-switch");

expect(await calciteSwitch.getProperty("checked")).toBe(true);
expect(await calciteSwitch.getProperty("switched")).toBe(true);
});

it("appropriately triggers the custom change event", async () => {
const page = await newE2EPage();
await page.setContent(`<calcite-switch></calcite-switch>`);
Expand All @@ -82,7 +72,6 @@ describe("calcite-switch", () => {
await calciteSwitch.click();

expect(changeEvent).toHaveReceivedEventTimes(1);
expect(changeEvent).toHaveFirstReceivedEventDetail({ switched: true });
});

it("doesn't emit when controlling checked attribute", async () => {
Expand Down
30 changes: 4 additions & 26 deletions src/components/switch/switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import {
Host,
Method,
Prop,
VNode,
Watch
VNode
} from "@stencil/core";
import { focusElement, toAriaBoolean } from "../../utils/dom";
import { DeprecatedEventPayload, Scale } from "../interfaces";
import { Scale } from "../interfaces";
import { LabelableComponent, connectLabel, disconnectLabel, getLabelText } from "../../utils/label";
import {
connectForm,
Expand Down Expand Up @@ -62,18 +61,6 @@ export class Switch
/** Specifies the size of the component. */
@Prop({ reflect: true }) scale: Scale = "m";

/**
* When `true`, the component is checked.
*
* @deprecated use `checked` instead.
*/
@Prop({ mutable: true, reflect: true }) switched = false;

@Watch("switched")
switchedWatcher(switched: boolean): void {
this.checked = switched;
}

/** When `true`, the component is checked. */
@Prop({ reflect: true, mutable: true }) checked = false;

Expand Down Expand Up @@ -132,9 +119,7 @@ export class Switch

private toggle(): void {
this.checked = !this.checked;
this.calciteSwitchChange.emit({
switched: this.checked
});
this.calciteSwitchChange.emit();
}

private clickHandler = (): void => {
Expand All @@ -156,7 +141,7 @@ export class Switch
*
* **Note:** The event payload is deprecated, use the component's `checked` property instead.
*/
@Event({ cancelable: false }) calciteSwitchChange: EventEmitter<DeprecatedEventPayload>;
@Event({ cancelable: false }) calciteSwitchChange: EventEmitter<void>;

//--------------------------------------------------------------------------
//
Expand All @@ -165,13 +150,6 @@ export class Switch
//--------------------------------------------------------------------------

connectedCallback(): void {
const initiallyChecked = this.checked || this.switched;

if (initiallyChecked) {
// if either prop is set, we ensure both are synced initially
this.switched = this.checked = initiallyChecked;
}

connectLabel(this);
connectForm(this);
}
Expand Down
2 changes: 1 addition & 1 deletion src/demos/switch.html
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ <h1 style="margin: 0 auto; text-align: center">Switch</h1>
<script>
const basicSwitch = document.getElementById("basicSwitch");
basicSwitch.addEventListener("calciteSwitchChange", function (e) {
console.log("Basic switch changed by <calcite-switch>", e.detail.switched);
console.log("Basic switch changed by <calcite-switch>", e.target.checked);
});
</script>
</demo-dom-swapper>
Expand Down

0 comments on commit 4ace1d3

Please sign in to comment.