Skip to content
Open
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
8 changes: 1 addition & 7 deletions packages/react-aria/src/interactions/usePress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -990,13 +990,7 @@ export function usePress(props: PressHookProps): PressResult {
// touchAction: 'manipulation' is supposed to be equivalent, but in
// Safari it causes onPointerCancel not to fire on scroll.
// https://bugs.webkit.org/show_bug.cgi?id=240917
style.textContent = `
@layer {
[${PRESSABLE_ATTRIBUTE}] {
touch-action: pan-x pan-y pinch-zoom;
}
}
`.trim();
style.textContent=`@layer{[${PRESSABLE_ATTRIBUTE}]{touch-action:pan-x pan-y pinch-zoom}}`
Comment thread
wojtekmaj marked this conversation as resolved.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead, I think we could handle this with a macro. Then we don't need to sacrifice readability and we get any smarts from css minifiers. It might be overkill given that we only do this twice and they are pretty small. @devongovett would appreciate your thoughts

import type {MacroContext} from '@parcel/macros';
import {transform} from 'lightningcss';

export function cssString(this: MacroContext | void, css: string): string {
  if ((this == null || this === globalThis) && process.env.NODE_ENV !== 'test') {
    throw new Error('The cssString macro must be imported with {type: "macro"}.');
  }

  try {
    let {code} = transform({
      filename: 'cssString.css',
      code: Buffer.from(css),
      minify: true,
      sourceMap: false
    });
    return code.toString();
  } catch (err) {
    throw new Error(`cssString macro: failed to parse or minify CSS: ${err}`);
  }
}

then call it like so:

    style.textContent = cssString(`
@layer {
  [${PRESSABLE_ATTRIBUTE}] {
    touch-action: pan-x pan-y pinch-zoom;
  }
}
    `);

ownerDocument.head.prepend(style);
}, [domRef]);

Expand Down
7 changes: 1 addition & 6 deletions packages/react-aria/src/overlays/usePreventScroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,7 @@ function preventScrollMobileSafari() {
if (nonce) {
style.nonce = nonce;
}
style.textContent = `
@layer {
* {
overscroll-behavior: contain;
}
}`.trim();
style.textContent='@layer{*{overscroll-behavior:contain}}'
Comment thread
wojtekmaj marked this conversation as resolved.
document.head.prepend(style);

let onTouchMove = (e: TouchEvent) => {
Expand Down
Loading