From 28addd49da71cd710cad6b475dea5828b438f018 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Mon, 13 Nov 2023 02:25:10 -0800 Subject: [PATCH] Make `Event#preventDefault()` only work when `cancelable: true` --- .changeset/lazy-adults-burn.md | 5 +++++ packages/runtime/src/polyfills/event.ts | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 .changeset/lazy-adults-burn.md diff --git a/.changeset/lazy-adults-burn.md b/.changeset/lazy-adults-burn.md new file mode 100644 index 00000000..a1dd58b3 --- /dev/null +++ b/.changeset/lazy-adults-burn.md @@ -0,0 +1,5 @@ +--- +'nxjs-runtime': patch +--- + +Make `Event#preventDefault()` only work when `cancelable: true` diff --git a/packages/runtime/src/polyfills/event.ts b/packages/runtime/src/polyfills/event.ts index 826269a5..dcba5cda 100644 --- a/packages/runtime/src/polyfills/event.ts +++ b/packages/runtime/src/polyfills/event.ts @@ -63,8 +63,10 @@ export class Event implements globalThis.Event { throw new Error('Method not implemented.'); } preventDefault(): void { - // @ts-expect-error - `defaultPrevented` is readonly - this.defaultPrevented = true; + if (this.cancelable) { + // @ts-expect-error - `defaultPrevented` is readonly + this.defaultPrevented = true; + } } stopImmediatePropagation(): void { throw new Error('Method not implemented.');