Skip to content

Commit

Permalink
Fix/remove non null assertion (#5353)
Browse files Browse the repository at this point in the history
* remove non-null assertion in anchored region

Change files

* Update packages/web-components/fast-components/src/anchored-region/anchored-region.stories.ts

Co-authored-by: Rob Barber <69695238+robarbms@users.noreply.github.com>

* Update packages/web-components/fast-components/src/anchored-region/anchored-region.stories.ts

Co-authored-by: Rob Barber <69695238+robarbms@users.noreply.github.com>

* fix prettier issue

Co-authored-by: Rob Barber <69695238+robarbms@users.noreply.github.com>
Co-authored-by: Chris Holt <chhol@microsoft.com>
  • Loading branch information
3 people authored Nov 5, 2021
1 parent 0308a3f commit e4ddc05
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "remove non-null assertion in anchored region",
"packageName": "@microsoft/fast-components",
"email": "mathieu.lavoie@shopify.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { AnchoredRegion as FoundationAnchoredRegion } from "@microsoft/fast-foun
import AnchoredRegionTemplate from "./fixtures/base.html";
import "./index";

/* eslint-disable @typescript-eslint/no-non-null-assertion */
addons.getChannel().addListener(STORY_RENDERED, (name: string) => {
if (name.toLowerCase().startsWith("anchored-region")) {
//scroll stuff into view
Expand Down Expand Up @@ -46,60 +45,60 @@ addons.getChannel().addListener(STORY_RENDERED, (name: string) => {
const regionScalingUpdate = document.getElementById(
"region-upd1"
) as FoundationAnchoredRegion;
document
.getElementById("viewport-upd1")!
.addEventListener("scroll", () => regionScalingUpdate.update());

const viewPort = document.getElementById("viewport-upd1");
const togglesRegion = document.getElementById("toggles-region");

if (!togglesRegion || !viewPort) {
return;
}

viewPort.addEventListener("scroll", () => regionScalingUpdate.update());

// toggle anchor example
document.querySelectorAll("[id^=toggles1-anchor").forEach(anchor => {
anchor.addEventListener("click", (e: MouseEvent) => {
togglesRegion!.setAttribute("anchor", (e.target as HTMLElement).id);
togglesRegion.setAttribute("anchor", (e.target as HTMLElement).id);
});
});

document
.getElementById("toggle-positions-horizontal")!
.addEventListener("click", (e: MouseEvent) => {
if (
togglesRegion?.getAttribute("horizontal-default-position") === "right"
) {
togglesRegion!.setAttribute("horizontal-default-position", "left");
} else {
togglesRegion!.setAttribute("horizontal-default-position", "right");
}
});

document
.getElementById("toggle-positions-vertical")!
.addEventListener("click", (e: MouseEvent) => {
if (togglesRegion?.getAttribute("vertical-default-position") === "top") {
togglesRegion!.setAttribute("vertical-default-position", "bottom");
} else {
togglesRegion!.setAttribute("vertical-default-position", "top");
}
});

document
.getElementById("toggle-inset-vertical")!
.addEventListener("click", (e: MouseEvent) => {
if (togglesRegion?.getAttribute("vertical-inset") === "true") {
togglesRegion!.setAttribute("vertical-inset", "false");
} else {
togglesRegion!.setAttribute("vertical-inset", "true");
}
});

document
.getElementById("toggle-inset-horizontal")!
.addEventListener("click", (e: MouseEvent) => {
if (togglesRegion?.getAttribute("horizontal-inset") === "true") {
togglesRegion!.setAttribute("horizontal-inset", "false");
} else {
togglesRegion!.setAttribute("horizontal-inset", "true");
}
});
[
{
id: "toggle-positions-horizontal",
attribute: "horizontal-default-position",
firstValue: "right",
secondValue: "left",
},
{
id: "toggle-positions-vertical",
attribute: "vertical-default-position",
firstValue: "top",
secondValue: "bottom",
},
{
id: "toggle-inset-vertical",
attribute: "vertical-inset",
firstValue: "true",
secondValue: "false",
},
{
id: "toggle-inset-horizontal",
attribute: "horizontal-inset",
firstValue: "true",
secondValue: "false",
},
].forEach(({ id, attribute, firstValue, secondValue }) => {
const toggleElement = document.getElementById(id);
if (toggleElement) {
toggleElement.addEventListener("click", () => {
togglesRegion.setAttribute(
attribute,
togglesRegion.getAttribute(attribute) === firstValue
? secondValue
: firstValue
);
});
}
});

document
.querySelectorAll("[id^=anchor-menu-many]")
Expand All @@ -120,4 +119,3 @@ export default {
};

export const AnchoredRegion = () => AnchoredRegionTemplate;
/* eslint-enable @typescript-eslint/no-non-null-assertion */

0 comments on commit e4ddc05

Please sign in to comment.