An open source design system that's fully customizable and agent ready
TypeScript
fix(Carousel): mirror single-edge fade gradients under RTL (#5586)
Matt Andrycfbfe729d12b1
diff --git a/.changeset/carousel-rtl-edge-fade.md b/.changeset/carousel-rtl-edge-fade.mdnew file mode 100644index 0000000000..1807b1d201--- /dev/null+++ b/.changeset/carousel-rtl-edge-fade.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] Carousel: mirror the single-edge fade gradients under RTL so the mask fades the physical edge that actually hides content (overflowStart/overflowEnd are logical edges, the gradients were always physical left/right)++@mattandrycdiff --git a/packages/core/src/Carousel/Carousel.test.tsx b/packages/core/src/Carousel/Carousel.test.tsxindex db2942b1d4..b294301d88 100644--- a/packages/core/src/Carousel/Carousel.test.tsx+++ b/packages/core/src/Carousel/Carousel.test.tsx@@ -850,4 +850,87 @@ describe('Carousel', () => {expect(scroller).not.toHaveAttribute('data-padding');});});++ describe('edge fade', () => {+ function getScroller() {+ const region = screen.getByRole('region');+ return region.firstElementChild as HTMLElement;+ }++ function makeOverflowing(el: HTMLElement, scrollLeft: number) {+ Object.defineProperty(el, 'scrollWidth', {+ value: 500,+ configurable: true,+ });+ Object.defineProperty(el, 'clientWidth', {+ value: 200,+ configurable: true,+ });+ Object.defineProperty(el, 'scrollLeft', {+ value: scrollLeft,+ writable: true,+ configurable: true,+ });+ fireEvent.scroll(el);+ }++ function injectedCss(): string {+ let out = '';+ for (const sheet of Array.from(document.styleSheets)) {+ try {+ for (const rule of Array.from(sheet.cssRules)) {+ out += rule.cssText + '\n';+ }+ } catch {+ // Ignore cross-origin sheets.+ }+ }+ return out;+ }++ it('fades the physical left edge when only the start overflows (LTR)', () => {+ render(+ <Carousel aria-label="Fade">+ <div>Item 1</div>+ <div>Item 2</div>+ </Carousel>,+ );+ const scroller = getScroller();+ makeOverflowing(scroller, 300);+ expect(getComputedStyle(scroller).maskImage).toContain(+ 'linear-gradient(to right',+ );+ });++ it('fades the physical right edge when only the end overflows (LTR)', () => {+ render(+ <Carousel aria-label="Fade">+ <div>Item 1</div>+ <div>Item 2</div>+ </Carousel>,+ );+ const scroller = getScroller();+ makeOverflowing(scroller, 0);+ expect(getComputedStyle(scroller).maskImage).toContain(+ 'linear-gradient(to left',+ );+ });++ it('mirrors both single-edge fade gradients under RTL', () => {+ render(+ <Carousel aria-label="Fade">+ <div>Item 1</div>+ <div>Item 2</div>+ </Carousel>,+ );+ const css = injectedCss();+ expect(css).toMatch(+ /:is\(\[dir="rtl"\][^)]*\)[^{]*\{\s*mask-image:\s*linear-gradient\(to left/,+ );+ expect(css).toMatch(+ /:is\(\[dir="rtl"\][^)]*\)[^{]*\{\s*mask-image:\s*linear-gradient\(to right/,+ );+ });+ });+});diff --git a/packages/core/src/Carousel/Carousel.tsx b/packages/core/src/Carousel/Carousel.tsxindex 8c08f1a120..fe69f019cf 100644--- a/packages/core/src/Carousel/Carousel.tsx+++ b/packages/core/src/Carousel/Carousel.tsx@@ -178,10 +178,16 @@ const styles = stylex.create({maskImage: 'none',},fadeStart: {- maskImage: `linear-gradient(to right, transparent 0%, rgba(0,0,0,0.3) 2px, black ${spacingVars['--spacing-1']})`,+ maskImage: {+ default: `linear-gradient(to right, transparent 0%, rgba(0,0,0,0.3) 2px, black ${spacingVars['--spacing-1']})`,+ ':is([dir="rtl"] *)': `linear-gradient(to left, transparent 0%, rgba(0,0,0,0.3) 2px, black ${spacingVars['--spacing-1']})`,+ },},fadeEnd: {- maskImage: `linear-gradient(to left, transparent 0%, rgba(0,0,0,0.3) 2px, black ${spacingVars['--spacing-1']})`,+ maskImage: {+ default: `linear-gradient(to left, transparent 0%, rgba(0,0,0,0.3) 2px, black ${spacingVars['--spacing-1']})`,+ ':is([dir="rtl"] *)': `linear-gradient(to right, transparent 0%, rgba(0,0,0,0.3) 2px, black ${spacingVars['--spacing-1']})`,+ },},fadeBoth: {maskImage: `linear-gradient(to right, transparent 0%, rgba(0,0,0,0.3) 2px, black ${spacingVars['--spacing-1']}, black calc(100% - ${spacingVars['--spacing-1']}), rgba(0,0,0,0.3) calc(100% - 2px), transparent 100%)`,