Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.
Go dockerfossgomarkdownmemomicroblognote-takingnotesopen-sourceown-your-datareactself-hostedsqlitetimeline
fix(web): correct RTL layout behavior (#6215)
ambluede67ec7935199
diff --git a/web/src/App.tsx b/web/src/App.tsxindex 21003fb64..58af79329 100644--- a/web/src/App.tsx+++ b/web/src/App.tsx@@ -1,3 +1,4 @@+import { DirectionProvider } from "@base-ui/react/direction-provider";import { useEffect } from "react";import { Outlet, ScrollRestoration } from "react-router-dom";import { useInstance } from "./contexts/InstanceContext";@@ -11,7 +12,7 @@ const App = () => {const { profile: instanceProfile, profileLoaded, generalSetting: instanceGeneralSetting } = useInstance();// Apply user preferences reactively- useUserLocale();+ const direction = useUserLocale();useUserTheme();// Clean up expired OAuth states on app initialization@@ -58,10 +59,10 @@ const App = () => {}, [instanceGeneralSetting.customProfile]);return (- <>+ <DirectionProvider direction={direction}><Outlet /><ScrollRestoration />- </>+ </DirectionProvider>);};diff --git a/web/src/components/ActivityCalendar/YearCalendar.tsx b/web/src/components/ActivityCalendar/YearCalendar.tsxindex c34b8f16e..e731ed881 100644--- a/web/src/components/ActivityCalendar/YearCalendar.tsx+++ b/web/src/components/ActivityCalendar/YearCalendar.tsx@@ -36,7 +36,7 @@ const YearNavigation = memo(({ selectedYear, currentYear, onPrev, onNext, onTodaaria-label="Previous year"className="size-7 rounded-md text-muted-foreground/65 hover:bg-muted/50 hover:text-foreground/90">- <ChevronLeftIcon className="size-[15px]" strokeWidth={1.75} />+ <ChevronLeftIcon className="size-[15px] rtl:rotate-180" strokeWidth={1.75} /></Button><Button@@ -63,7 +63,7 @@ const YearNavigation = memo(({ selectedYear, currentYear, onPrev, onNext, onTodaaria-label="Next year"className="size-7 rounded-md text-muted-foreground/65 hover:bg-muted/50 hover:text-foreground/90">- <ChevronRightIcon className="size-[15px]" strokeWidth={1.75} />+ <ChevronRightIcon className="size-[15px] rtl:rotate-180" strokeWidth={1.75} /></Button></nav></div>diff --git a/web/src/components/AppSidebar/AppSidebar.tsx b/web/src/components/AppSidebar/AppSidebar.tsxindex 446cd5d97..44517b668 100644--- a/web/src/components/AppSidebar/AppSidebar.tsx+++ b/web/src/components/AppSidebar/AppSidebar.tsx@@ -1,3 +1,4 @@+import { useDirection } from "@base-ui/react/direction-provider";import { useQueryClient } from "@tanstack/react-query";import {ArchiveIcon,@@ -644,7 +645,7 @@ const AppSidebar = ({ className }: { className?: string }) => {<span className="truncate">{t("common.sign-in-to-memos")}</span></span><ArrowRightIcon- className="size-3.5 shrink-0 text-muted-foreground/60 transition-transform group-hover:translate-x-0.5"+ className="size-3.5 shrink-0 text-muted-foreground/60 transition-transform group-hover:translate-x-0.5 rtl:rotate-180 rtl:group-hover:-translate-x-0.5"strokeWidth={1.8}/></Link>@@ -673,10 +674,14 @@ export const MobileAppHeader = () => {};export const MobileAppSidebar = () => {+ const direction = useDirection();const { mobileOpen, setMobileOpen } = useAppSidebar();return (<Sheet open={mobileOpen} onOpenChange={setMobileOpen}>- <SheetContent side="left" className="w-[min(18rem,calc(100vw-2rem))] gap-0 border-border p-0 shadow-2xl [&>button]:hidden">+ <SheetContent+ side={direction === "rtl" ? "right" : "left"}+ className="w-[min(18rem,calc(100vw-2rem))] gap-0 border-border p-0 shadow-2xl [&>button]:hidden"+ ><SheetTitle className="sr-only">Navigation</SheetTitle><AppSidebar /></SheetContent>diff --git a/web/src/components/AppSidebar/SidebarResizeHandle.tsx b/web/src/components/AppSidebar/SidebarResizeHandle.tsxindex 6686ac17d..dfc5318cc 100644--- a/web/src/components/AppSidebar/SidebarResizeHandle.tsx+++ b/web/src/components/AppSidebar/SidebarResizeHandle.tsx@@ -1,3 +1,4 @@+import { useDirection } from "@base-ui/react/direction-provider";import {type KeyboardEvent as ReactKeyboardEvent,type PointerEvent as ReactPointerEvent,@@ -25,6 +26,7 @@ interface Props {const SidebarResizeHandle = ({ width, minWidth, maxWidth, onWidthChange, targetRef }: Props) => {const t = useTranslate();+ const direction = useDirection();// `dragging` drives the band's styling; `draggingRef` is what the handlers and the unmount// cleanup read, so neither depends on a state update having been flushed first.const [dragging, setDragging] = useState(false);@@ -99,7 +101,8 @@ const SidebarResizeHandle = ({ width, minWidth, maxWidth, onWidthChange, targetRif (!draggingRef.current) return;// Track the delta rather than the raw cursor x, so grabbing anywhere in the strip// does not snap the rail's edge to the pointer.- previewWidth(clamp(originRef.current.width + event.clientX - originRef.current.x));+ const pointerDelta = event.clientX - originRef.current.x;+ previewWidth(clamp(originRef.current.width + (direction === "rtl" ? -pointerDelta : pointerDelta)));};const endDrag = (event: ReactPointerEvent<HTMLDivElement>) => {@@ -114,11 +117,12 @@ const SidebarResizeHandle = ({ width, minWidth, maxWidth, onWidthChange, targetR};const handleKeyDown = (event: ReactKeyboardEvent<HTMLDivElement>) => {+ const horizontalStep = direction === "rtl" ? -KEYBOARD_STEP : KEYBOARD_STEP;const next =event.key === "ArrowLeft"- ? width - KEYBOARD_STEP+ ? width - horizontalStep: event.key === "ArrowRight"- ? width + KEYBOARD_STEP+ ? width + horizontalStep: event.key === "Home"? minWidth: event.key === "End"@@ -144,7 +148,7 @@ const SidebarResizeHandle = ({ width, minWidth, maxWidth, onWidthChange, targetRonPointerCancel={endDrag}onDoubleClick={() => onWidthChange(SIDEBAR_DEFAULT_WIDTH)}onKeyDown={handleKeyDown}- className="group absolute inset-y-0 -right-1 z-10 flex w-2 cursor-col-resize touch-none justify-center focus-visible:outline-none"+ className="group absolute inset-y-0 -end-1 z-10 flex w-2 cursor-col-resize touch-none justify-center focus-visible:outline-none">{/* A 2px band centering to whole pixels inside the 8px strip, so it covers the rail'sborder and stays crisp at 1x instead of antialiasing across a half-pixel seam. */}diff --git a/web/src/components/AuthPageLayout.tsx b/web/src/components/AuthPageLayout.tsxindex bdfee90e3..715eabfb2 100644--- a/web/src/components/AuthPageLayout.tsx+++ b/web/src/components/AuthPageLayout.tsx@@ -78,7 +78,7 @@ const AuthPageLayout = ({ chip, title, subtitle, hideExplore, children }: Props)><CompassIcon className="h-3.5 w-3.5" />{t("auth.explore-public-memos")}- <ArrowRightIcon className="-ml-1 h-3.5 w-3.5 opacity-0 transition-all group-hover:ml-0 group-hover:opacity-100" />+ <ArrowRightIcon className="-ms-1 h-3.5 w-3.5 opacity-0 transition-all group-hover:ms-0 group-hover:opacity-100 rtl:rotate-180" /></Link></div>)}diff --git a/web/src/components/ColumnGrid/ColumnGrid.tsx b/web/src/components/ColumnGrid/ColumnGrid.tsxindex 0ed295d14..2081a1f94 100644--- a/web/src/components/ColumnGrid/ColumnGrid.tsx+++ b/web/src/components/ColumnGrid/ColumnGrid.tsx@@ -1,3 +1,4 @@+import { useDirection } from "@base-ui/react/direction-provider";import { type ReactNode, useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";interface ColumnGridProps<T> {@@ -79,6 +80,7 @@ function ColumnGrid<T>({maxColumns,maxColumnWidth,}: ColumnGridProps<T>) {+ const direction = useDirection();const containerRef = useRef<HTMLDivElement>(null);const itemRefs = useRef<Map<string, HTMLDivElement>>(new Map());const refCallbacks = useRef<Map<string, (el: HTMLDivElement | null) => void>>(new Map());@@ -156,7 +158,8 @@ function ColumnGrid<T>({const pos = new Map<string, { x: number; y: number }>();for (const { key } of ordered) {const col = columnOf.get(key) ?? 0;- const x = offsetX + col * (columnWidth + GRID_GAP);+ const inlineOffset = offsetX + col * (columnWidth + GRID_GAP);+ const x = direction === "rtl" ? width - columnWidth - inlineOffset : inlineOffset;const y = columnY[col];pos.set(key, { x, y });columnY[col] = y + heightOf(key) + GRID_GAP;@@ -185,7 +188,7 @@ function ColumnGrid<T>({}setContainerHeight(Math.max(0, ...columnY.map((h) => h - GRID_GAP)));- }, [items, getKey, estimateHeight, priorityKey, maxColumns, maxColumnWidth]);+ }, [items, getKey, estimateHeight, priorityKey, maxColumns, maxColumnWidth, direction]);// Keep a stable reference so observer callbacks always run the latest layout.const relayoutRef = useRef(relayout);diff --git a/web/src/components/MemoContent/LinkMetadataCard.tsx b/web/src/components/MemoContent/LinkMetadataCard.tsxindex ebc77a293..36d2a329c 100644--- a/web/src/components/MemoContent/LinkMetadataCard.tsx+++ b/web/src/components/MemoContent/LinkMetadataCard.tsx@@ -51,7 +51,7 @@ const LinkMetadataCard = ({ url, fallback, enabled = true }: LinkMetadataCardPro{description && <span className="line-clamp-1 text-xs leading-4 text-muted-foreground sm:line-clamp-2">{description}</span>}</span>{image && !imageFailed && (- <span className="flex w-24 shrink-0 items-center border-l border-border/70 bg-muted/40 sm:w-40">+ <span className="flex w-24 shrink-0 items-center border-s border-border/70 bg-muted/40 sm:w-40"><span className="aspect-[1.91/1] w-full overflow-hidden"><imgsrc={image}diff --git a/web/src/components/MemoDetailSidebar/MemoOutline.tsx b/web/src/components/MemoDetailSidebar/MemoOutline.tsxindex bd88fec38..379e2c0b9 100644--- a/web/src/components/MemoDetailSidebar/MemoOutline.tsx+++ b/web/src/components/MemoDetailSidebar/MemoOutline.tsx@@ -78,11 +78,11 @@ const MemoOutline = ({ headings, memoName }: MemoOutlineProps) => {heading.level === minLevel && "font-medium",active ? "text-foreground" : "text-muted-foreground/70 hover:bg-sidebar-accent/65 hover:text-foreground",)}- style={{ paddingLeft: 8 + (heading.level - minLevel) * 12 }}+ style={{ paddingInlineStart: 8 + (heading.level - minLevel) * 12 }}><spanclassName={cn(- "absolute left-0.5 top-1/2 h-[13px] w-[2px] -translate-y-1/2 rounded-full transition-colors",+ "absolute start-0.5 top-1/2 h-[13px] w-[2px] -translate-y-1/2 rounded-full transition-colors",active ? "bg-primary" : "bg-border",)}/>diff --git a/web/src/components/MemoDisplaySettingMenu.tsx b/web/src/components/MemoDisplaySettingMenu.tsxindex 0f3f72c4d..69e1c0905 100644--- a/web/src/components/MemoDisplaySettingMenu.tsx+++ b/web/src/components/MemoDisplaySettingMenu.tsx@@ -1,3 +1,4 @@+import { useDirection } from "@base-ui/react/direction-provider";import { Columns2Icon, Columns3Icon, InfinityIcon, type LucideIcon, Rows3Icon, SlidersHorizontalIcon } from "lucide-react";import type { ReactNode } from "react";import { SIDEBAR_SECTION_ACTION_BUTTON_CLASSES, SIDEBAR_SECTION_ACTION_ICON_CLASSES } from "@/components/AppSidebar/SidebarSection";@@ -41,6 +42,7 @@ const SettingRow = ({ label, description, children }: SettingRowProps) => (function MemoDisplaySettingsContent() {const t = useTranslate();+ const direction = useDirection();const {orderByTimeAsc,timeBasis,@@ -76,7 +78,19 @@ function MemoDisplaySettingsContent() {className="grid grid-cols-4 gap-0.5 rounded-lg bg-muted/55 p-0.5"onKeyDown={(event) => {const delta =- event.key === "ArrowRight" || event.key === "ArrowDown" ? 1 : event.key === "ArrowLeft" || event.key === "ArrowUp" ? -1 : 0;+ event.key === "ArrowRight"+ ? direction === "rtl"+ ? -1+ : 1+ : event.key === "ArrowLeft"+ ? direction === "rtl"+ ? 1+ : -1+ : event.key === "ArrowDown"+ ? 1+ : event.key === "ArrowUp"+ ? -1+ : 0;if (delta === 0) return;event.preventDefault();const index = MAX_COLUMNS_VALUES.indexOf(maxColumns);diff --git a/web/src/components/MemoEditor/components/AudioRecorderPanel.tsx b/web/src/components/MemoEditor/components/AudioRecorderPanel.tsxindex 0d0ccd2f5..ff71acc86 100644--- a/web/src/components/MemoEditor/components/AudioRecorderPanel.tsx+++ b/web/src/components/MemoEditor/components/AudioRecorderPanel.tsx@@ -49,7 +49,7 @@ export const AudioRecorderPanel: FC<AudioRecorderPanelProps> = ({</span></div>- <div className="flex shrink-0 items-center gap-1 border-l border-border/60 pl-2">+ <div className="flex shrink-0 items-center gap-1 border-s border-border/60 ps-2"><Buttontype="button"variant="ghost"@@ -63,7 +63,7 @@ export const AudioRecorderPanel: FC<AudioRecorderPanelProps> = ({</Button>{canTranscribe && (<Tooltip>- <TooltipTrigger render={<span className="-ml-2 inline-flex" />}>+ <TooltipTrigger render={<span className="-ms-2 inline-flex" />}><Buttontype="button"variant="ghost"diff --git a/web/src/components/MemoMetadata/Attachment/AudioAttachmentItem.tsx b/web/src/components/MemoMetadata/Attachment/AudioAttachmentItem.tsxindex 6d8873dbe..8933c1a76 100644--- a/web/src/components/MemoMetadata/Attachment/AudioAttachmentItem.tsx+++ b/web/src/components/MemoMetadata/Attachment/AudioAttachmentItem.tsx@@ -28,7 +28,7 @@ const AudioProgressBar = ({ filename, currentTime, duration, progressPercent, on<div className={`flex items-center gap-2 ${className ?? ""}`}><div className="relative flex h-3.5 min-w-0 flex-1 items-center"><div className="absolute inset-x-0 h-1 rounded-full bg-muted/75" />- <div className="absolute left-0 h-1 rounded-full bg-foreground/20" style={{ width: `${Math.min(progressPercent, 100)}%` }} />+ <div className="absolute start-0 h-1 rounded-full bg-foreground/20" style={{ width: `${Math.min(progressPercent, 100)}%` }} /><inputtype="range"min={0}diff --git a/web/src/components/Settings/AccessTokenSection.tsx b/web/src/components/Settings/AccessTokenSection.tsxindex 53a6587c1..43bce8665 100644--- a/web/src/components/Settings/AccessTokenSection.tsx+++ b/web/src/components/Settings/AccessTokenSection.tsx@@ -29,10 +29,10 @@ const ApiUsageExample = () => {return (<div className="relative w-full min-w-0 rounded-lg border border-border/60 bg-muted/30">- <pre className="overflow-x-auto p-3 pr-12 font-mono text-xs leading-5 text-foreground/85">+ <pre className="overflow-x-auto p-3 pe-12 font-mono text-xs leading-5 text-foreground/85"><code>{example}</code></pre>- <Button variant="ghost" size="icon" className="absolute top-1.5 right-1.5" aria-label={t("common.copy")} onClick={handleCopy}>+ <Button variant="ghost" size="icon" className="absolute top-1.5 end-1.5" aria-label={t("common.copy")} onClick={handleCopy}><CopyIcon className="w-3.5 h-auto" /></Button></div>@@ -78,7 +78,7 @@ const HowToUseDisclosure = () => {aria-expanded={open}onClick={() => setOpen((v) => !v)}>- <ChevronRightIcon className={`size-3.5 transition-transform ${open ? "rotate-90" : ""}`} />+ <ChevronRightIcon className={`size-3.5 transition-transform ${open ? "rotate-90" : "rtl:rotate-180"}`} />{t("setting.access-token.how-to-use")}</button>{open && (diff --git a/web/src/components/StatisticsView/MonthNavigator.tsx b/web/src/components/StatisticsView/MonthNavigator.tsxindex 455be6e9b..83ad4c675 100644--- a/web/src/components/StatisticsView/MonthNavigator.tsx+++ b/web/src/components/StatisticsView/MonthNavigator.tsx@@ -26,7 +26,7 @@ export const MonthNavigator = memo(({ visibleMonth, onMonthChange }: MonthNavigaaria-label={t("common.previous-month")}className="size-6 rounded text-muted-foreground/65 hover:bg-muted/50 hover:text-foreground/90">- <ChevronLeftIcon className="size-4" strokeWidth={1.75} />+ <ChevronLeftIcon className="size-4 rtl:rotate-180" strokeWidth={1.75} /></Button><Button@@ -36,7 +36,7 @@ export const MonthNavigator = memo(({ visibleMonth, onMonthChange }: MonthNavigaaria-label={t("common.next-month")}className="size-6 rounded text-muted-foreground/65 hover:bg-muted/50 hover:text-foreground/90">- <ChevronRightIcon className="size-4" strokeWidth={1.75} />+ <ChevronRightIcon className="size-4 rtl:rotate-180" strokeWidth={1.75} /></Button></nav></header>diff --git a/web/src/components/TagTree.tsx b/web/src/components/TagTree.tsxindex d88f69666..7319ef85a 100644--- a/web/src/components/TagTree.tsx+++ b/web/src/components/TagTree.tsx@@ -82,7 +82,7 @@ const TagMark = () => <HashIcon aria-hidden="true" className={SIDEBAR_ROW_ICON_Cconst Chevron = ({ open }: { open: boolean }) => (<ChevronRightIconaria-hidden="true"- className={cn("size-3.5 shrink-0 text-muted-foreground/70 transition-transform", open && "rotate-90")}+ className={cn("size-3.5 shrink-0 text-muted-foreground/70 transition-transform", open ? "rotate-90" : "rtl:rotate-180")}strokeWidth={1.8}/>);diff --git a/web/src/components/ui/dialog.tsx b/web/src/components/ui/dialog.tsxindex 169f800c3..5e2dd5063 100644--- a/web/src/components/ui/dialog.tsx+++ b/web/src/components/ui/dialog.tsx@@ -64,7 +64,7 @@ const DialogContent = React.forwardRef<><div className="overflow-y-auto overflow-x-hidden flex-1 flex flex-col gap-4">{children}</div>{showCloseButton && (- <DialogPrimitive.Close className="ring-offset-background absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4">+ <DialogPrimitive.Close className="ring-offset-background absolute top-4 end-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4"><XIcon /><span className="sr-only">Close</span></DialogPrimitive.Close>@@ -75,7 +75,7 @@ const DialogContent = React.forwardRef<DialogContent.displayName = "DialogContent";const DialogHeader = React.forwardRef<React.ElementRef<"div">, React.ComponentPropsWithoutRef<"div">>(({ className, ...props }, ref) => (- <div ref={ref} className={cn("flex flex-col gap-2 text-center sm:text-left", className)} {...props} />+ <div ref={ref} className={cn("flex flex-col gap-2 text-center sm:text-start", className)} {...props} />));DialogHeader.displayName = "DialogHeader";diff --git a/web/src/components/ui/dropdown-menu.tsx b/web/src/components/ui/dropdown-menu.tsxindex 8b686e29e..1d3be49e4 100644--- a/web/src/components/ui/dropdown-menu.tsx+++ b/web/src/components/ui/dropdown-menu.tsx@@ -79,8 +79,8 @@ function DropdownMenuItem({className={cn("data-highlighted:bg-accent data-highlighted:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:data-highlighted:bg-destructive/10 data-[variant=destructive]:data-highlighted:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center rounded-sm outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0",size === "sm"- ? "min-h-7 gap-1.5 px-2 py-1 text-ui data-[inset]:pl-7 [&_svg:not([class*='size-'])]:size-3.5"- : "gap-2 px-2 py-1.5 text-sm data-[inset]:pl-8 [&_svg:not([class*='size-'])]:size-4",+ ? "min-h-7 gap-1.5 px-2 py-1 text-ui data-[inset]:ps-7 [&_svg:not([class*='size-'])]:size-3.5"+ : "gap-2 px-2 py-1.5 text-sm data-[inset]:ps-8 [&_svg:not([class*='size-'])]:size-4",className,)}{...props}@@ -97,14 +97,14 @@ function DropdownMenuCheckboxItem({ className, children, checked, ...props }: DrclassName={cn("data-highlighted:bg-accent data-highlighted:text-accent-foreground relative flex cursor-default items-center rounded-sm outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0",size === "sm"- ? "min-h-7 gap-1.5 py-1 pr-2 pl-7 text-ui [&_svg:not([class*='size-'])]:size-3.5"- : "gap-2 py-1.5 pr-2 pl-8 text-sm [&_svg:not([class*='size-'])]:size-4",+ ? "min-h-7 gap-1.5 py-1 pe-2 ps-7 text-ui [&_svg:not([class*='size-'])]:size-3.5"+ : "gap-2 py-1.5 pe-2 ps-8 text-sm [&_svg:not([class*='size-'])]:size-4",className,)}checked={checked}{...props}>- <span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">+ <span className="pointer-events-none absolute start-2 flex size-3.5 items-center justify-center"><DropdownMenuPrimitive.CheckboxItemIndicator><CheckIcon className={size === "sm" ? "size-3.5" : "size-4"} /></DropdownMenuPrimitive.CheckboxItemIndicator>@@ -127,13 +127,13 @@ function DropdownMenuRadioItem({ className, children, ...props }: DropdownMenuPrclassName={cn("data-highlighted:bg-accent data-highlighted:text-accent-foreground relative flex cursor-default items-center rounded-sm outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0",size === "sm"- ? "min-h-7 gap-1.5 py-1 pr-2 pl-7 text-ui [&_svg:not([class*='size-'])]:size-3.5"- : "gap-2 py-1.5 pr-2 pl-8 text-sm [&_svg:not([class*='size-'])]:size-4",+ ? "min-h-7 gap-1.5 py-1 pe-2 ps-7 text-ui [&_svg:not([class*='size-'])]:size-3.5"+ : "gap-2 py-1.5 pe-2 ps-8 text-sm [&_svg:not([class*='size-'])]:size-4",className,)}{...props}>- <span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">+ <span className="pointer-events-none absolute start-2 flex size-3.5 items-center justify-center"><DropdownMenuPrimitive.RadioItemIndicator><CircleIcon className="size-2 fill-current" /></DropdownMenuPrimitive.RadioItemIndicator>@@ -156,7 +156,7 @@ function DropdownMenuLabel({<DropdownMenuPrimitive.GroupLabeldata-slot="dropdown-menu-label"data-inset={inset}- className={cn("px-2 font-medium", size === "sm" ? "py-1 text-ui data-[inset]:pl-7" : "py-1.5 text-sm data-[inset]:pl-8", className)}+ className={cn("px-2 font-medium", size === "sm" ? "py-1 text-ui data-[inset]:ps-7" : "py-1.5 text-sm data-[inset]:ps-8", className)}{...props}/>);@@ -180,7 +180,7 @@ function DropdownMenuShortcut({ className, ...props }: React.ComponentProps<"spareturn (<spandata-slot="dropdown-menu-shortcut"- className={cn("text-muted-foreground ml-auto tracking-widest", size === "sm" ? "text-2xs" : "text-xs", className)}+ className={cn("text-muted-foreground ms-auto tracking-widest", size === "sm" ? "text-2xs" : "text-xs", className)}{...props}/>);@@ -207,14 +207,14 @@ function DropdownMenuSubTrigger({className={cn("data-highlighted:bg-accent data-highlighted:text-accent-foreground data-popup-open:bg-accent data-popup-open:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center rounded-sm outline-hidden select-none [&_svg]:pointer-events-none [&_svg]:shrink-0",size === "sm"- ? "min-h-7 gap-1.5 px-2 py-1 text-ui data-[inset]:pl-7 [&_svg:not([class*='size-'])]:size-3.5"- : "gap-2 px-2 py-1.5 text-sm data-[inset]:pl-8 [&_svg:not([class*='size-'])]:size-4",+ ? "min-h-7 gap-1.5 px-2 py-1 text-ui data-[inset]:ps-7 [&_svg:not([class*='size-'])]:size-3.5"+ : "gap-2 px-2 py-1.5 text-sm data-[inset]:ps-8 [&_svg:not([class*='size-'])]:size-4",className,)}{...props}>{children}- <ChevronRightIcon className={cn("ml-auto", size === "sm" ? "size-3.5" : "size-4")} />+ <ChevronRightIcon className={cn("ms-auto rtl:rotate-180", size === "sm" ? "size-3.5" : "size-4")} /></DropdownMenuPrimitive.SubmenuTrigger>);}@@ -226,7 +226,7 @@ function DropdownMenuSubContent({ className, size, ...props }: DropdownMenuConte<DropdownMenuContentalign="start"alignOffset={-3}- side="right"+ side="inline-end"sideOffset={0}size={size ?? inheritedSize}className={cn("w-auto", className)}diff --git a/web/src/components/ui/popup.ts b/web/src/components/ui/popup.tsindex a923701f9..1e234d650 100644--- a/web/src/components/ui/popup.ts+++ b/web/src/components/ui/popup.ts@@ -8,4 +8,4 @@// and everything below shifts (#6154). Space a stack that contains a popup trigger with// `flex flex-col gap-*`, which ignores out-of-flow children.export const popupMotionClasses =- "transition-[opacity,scale,translate] duration-150 data-starting-style:scale-95 data-starting-style:opacity-0 data-ending-style:scale-95 data-ending-style:opacity-0 data-[side=bottom]:data-starting-style:-translate-y-2 data-[side=bottom]:data-ending-style:-translate-y-2 data-[side=left]:data-starting-style:translate-x-2 data-[side=left]:data-ending-style:translate-x-2 data-[side=right]:data-starting-style:-translate-x-2 data-[side=right]:data-ending-style:-translate-x-2 data-[side=top]:data-starting-style:translate-y-2 data-[side=top]:data-ending-style:translate-y-2";+ "transition-[opacity,scale,translate] duration-150 data-starting-style:scale-95 data-starting-style:opacity-0 data-ending-style:scale-95 data-ending-style:opacity-0 data-[side=bottom]:data-starting-style:-translate-y-2 data-[side=bottom]:data-ending-style:-translate-y-2 data-[side=left]:data-starting-style:translate-x-2 data-[side=left]:data-ending-style:translate-x-2 data-[side=right]:data-starting-style:-translate-x-2 data-[side=right]:data-ending-style:-translate-x-2 data-[side=inline-start]:data-starting-style:translate-x-2 data-[side=inline-start]:data-ending-style:translate-x-2 rtl:data-[side=inline-start]:data-starting-style:-translate-x-2 rtl:data-[side=inline-start]:data-ending-style:-translate-x-2 data-[side=inline-end]:data-starting-style:-translate-x-2 data-[side=inline-end]:data-ending-style:-translate-x-2 rtl:data-[side=inline-end]:data-starting-style:translate-x-2 rtl:data-[side=inline-end]:data-ending-style:translate-x-2 data-[side=top]:data-starting-style:translate-y-2 data-[side=top]:data-ending-style:translate-y-2";diff --git a/web/src/components/ui/select.tsx b/web/src/components/ui/select.tsxindex 41b04f71d..4660ceb03 100644--- a/web/src/components/ui/select.tsx+++ b/web/src/components/ui/select.tsx@@ -106,13 +106,15 @@ function SelectItem({ className, children, ...props }: SelectPrimitive.Item.Prop<SelectPrimitive.Itemdata-slot="select-item"className={cn(- "data-highlighted:bg-accent data-highlighted:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",+ "data-highlighted:bg-accent data-highlighted:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pe-8 ps-2 text-sm outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",className,)}{...props}><SelectPrimitive.ItemText className="shrink-0 whitespace-nowrap">{children}</SelectPrimitive.ItemText>- <SelectPrimitive.ItemIndicator render={<span className="absolute right-2 flex size-3.5 items-center justify-center" />}>+ <SelectPrimitive.ItemIndicator+ render={<span data-slot="select-item-indicator" className="absolute end-2 flex size-3.5 items-center justify-center" />}+ ><CheckIcon className="size-4" /></SelectPrimitive.ItemIndicator></SelectPrimitive.Item>diff --git a/web/src/components/ui/sheet.tsx b/web/src/components/ui/sheet.tsxindex 1e1178bc9..1eb670079 100644--- a/web/src/components/ui/sheet.tsx+++ b/web/src/components/ui/sheet.tsx@@ -63,7 +63,7 @@ const SheetContent = React.forwardRef<{...props}>{children}- <SheetPrimitive.Close className="ring-offset-background absolute top-4 right-4 rounded-xs opacity-60 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none">+ <SheetPrimitive.Close className="ring-offset-background absolute top-4 end-4 rounded-xs opacity-60 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none"><XIcon className="size-5" /><span className="sr-only">Close</span></SheetPrimitive.Close>diff --git a/web/src/components/ui/switch.tsx b/web/src/components/ui/switch.tsxindex d57ca34ab..25413fbf7 100644--- a/web/src/components/ui/switch.tsx+++ b/web/src/components/ui/switch.tsx@@ -14,7 +14,7 @@ function Switch({ className, ...props }: SwitchPrimitive.Root.Props) {<SwitchPrimitive.Thumbdata-slot="switch-thumb"className={cn(- "bg-background pointer-events-none block size-4 rounded-full ring-0 transition-transform data-checked:translate-x-[calc(100%-2px)] data-unchecked:translate-x-0",+ "bg-background pointer-events-none block size-4 rounded-full ring-0 transition-transform data-checked:translate-x-[calc(100%-2px)] data-unchecked:translate-x-0 rtl:data-checked:-translate-x-[calc(100%-2px)]",)}/></SwitchPrimitive.Root>diff --git a/web/src/hooks/useUserLocale.ts b/web/src/hooks/useUserLocale.tsindex cd3946c3b..eae576efc 100644--- a/web/src/hooks/useUserLocale.ts+++ b/web/src/hooks/useUserLocale.ts@@ -1,15 +1,14 @@-import { useEffect } from "react";-import { useTranslation } from "react-i18next";+import { useEffect, useSyncExternalStore } from "react";import { useAuth } from "@/contexts/AuthContext";-import { getLocaleWithFallback, loadLocale } from "@/utils/i18n";+import { getLocaleDirection, getLocaleWithFallback, type LocaleDirection, loadLocale, subscribeToLocaleDirection } from "@/utils/i18n";/*** Hook that reactively applies user locale preference.* Priority: User setting → localStorage → browser language*/export const useUserLocale = () => {- const { i18n } = useTranslation();const { userGeneralSetting } = useAuth();+ const direction = useSyncExternalStore<LocaleDirection>(subscribeToLocaleDirection, getLocaleDirection, () => "ltr");// Apply locale when user setting changes or user logs inuseEffect(() => {@@ -20,16 +19,5 @@ export const useUserLocale = () => {loadLocale(locale);}, [userGeneralSetting?.locale]);- // Update HTML lang and dir attributes based on current locale- useEffect(() => {- const currentLocale = i18n.language;- document.documentElement.setAttribute("lang", currentLocale);-- // RTL languages- if (["ar", "fa", "he"].includes(currentLocale)) {- document.documentElement.setAttribute("dir", "rtl");- } else {- document.documentElement.setAttribute("dir", "ltr");- }- }, [i18n.language]);+ return direction;};diff --git a/web/src/layouts/RootLayout.tsx b/web/src/layouts/RootLayout.tsxindex f3666e421..f8908bf60 100644--- a/web/src/layouts/RootLayout.tsx+++ b/web/src/layouts/RootLayout.tsx@@ -70,7 +70,7 @@ const RootLayoutContent = () => {<AppSidebarProvider><div ref={shellRef} className="min-h-full w-full bg-background" style={{ [SIDEBAR_WIDTH_VAR]: `${sidebarWidth}px` } as CSSProperties}>{md && (- <div className="fixed inset-y-0 left-0 z-30 w-(--app-sidebar-width) border-r border-border/70">+ <div className="fixed inset-y-0 start-0 z-30 w-(--app-sidebar-width) border-e border-border/70"><AppSidebar /><SidebarResizeHandlewidth={sidebarWidth}@@ -82,7 +82,7 @@ const RootLayoutContent = () => {</div>)}<MobileAppSidebar />- <main className="flex min-h-full w-full min-w-0 flex-col items-center md:pl-(--app-sidebar-width)">+ <main className="flex min-h-full w-full min-w-0 flex-col items-center md:ps-(--app-sidebar-width)"><MobileAppHeader />{profile.demo && <DemoBanner />}<Outlet />diff --git a/web/src/lib/markdownStyles.ts b/web/src/lib/markdownStyles.tsindex 3edef3b2d..e838b2fd9 100644--- a/web/src/lib/markdownStyles.ts+++ b/web/src/lib/markdownStyles.ts@@ -40,9 +40,9 @@ const headingClasses: Record<HeadingLevel, string> = {*/export const markdownStyles = {paragraph: "my-0 mb-2 leading-6",- blockquote: "my-0 mb-2 border-l-4 border-primary/30 pl-3 text-muted-foreground italic",- bulletList: "my-0 mb-2 list-outside pl-6 list-disc",- orderedList: "my-0 mb-2 list-outside pl-6 list-decimal",+ blockquote: "my-0 mb-2 border-s-4 border-primary/30 ps-3 text-muted-foreground italic",+ bulletList: "my-0 mb-2 list-outside ps-6 list-disc",+ orderedList: "my-0 mb-2 list-outside ps-6 list-decimal",listItem: "mt-0.5 leading-6",// Shared by the read-only task item (MemoContent/markdown/List.tsx) and the// editor so the checkbox + text grid stays identical in both.diff --git a/web/src/pages/AdminSignIn.tsx b/web/src/pages/AdminSignIn.tsxindex 56ee55995..1b4520c44 100644--- a/web/src/pages/AdminSignIn.tsx+++ b/web/src/pages/AdminSignIn.tsx@@ -22,7 +22,7 @@ const AdminSignIn = () => {<PasswordSignInForm /><p className="mt-5 text-center text-sm"><Link to={ROUTES.AUTH} className="inline-flex items-center gap-1 text-primary hover:underline" viewTransition>- <ArrowLeftIcon className="h-3.5 w-3.5" />+ <ArrowLeftIcon className="h-3.5 w-3.5 rtl:rotate-180" />{t("auth.back-to-sign-in")}</Link></p>diff --git a/web/src/pages/SignIn.tsx b/web/src/pages/SignIn.tsxindex c0e377b85..678cdf5b8 100644--- a/web/src/pages/SignIn.tsx+++ b/web/src/pages/SignIn.tsx@@ -55,7 +55,7 @@ const SignIn = () => {><Link to={ROUTES.AUTH_ADMIN} className="mt-3 inline-flex items-center gap-1 text-sm text-primary hover:underline" viewTransition>{t("auth.admin-sign-in")}- <ArrowRightIcon className="h-3.5 w-3.5" />+ <ArrowRightIcon className="h-3.5 w-3.5 rtl:rotate-180" /></Link></AuthEmptyState>)}diff --git a/web/src/utils/i18n.ts b/web/src/utils/i18n.tsindex 4b1090e3c..5b26c1204 100644--- a/web/src/utils/i18n.ts+++ b/web/src/utils/i18n.ts@@ -4,6 +4,31 @@ import i18n, { locales, TLocale } from "@/i18n";import enTranslation from "@/locales/en.json";const LOCALE_STORAGE_KEY = "memos-locale";+const LOCALE_DIRECTION_CHANGE_EVENT = "memos:locale-direction-change";++export type LocaleDirection = "ltr" | "rtl";++export const getLocaleDirection = (): LocaleDirection =>+ typeof document !== "undefined" && document.documentElement.dir === "rtl" ? "rtl" : "ltr";++export const subscribeToLocaleDirection = (listener: () => void): (() => void) => {+ if (typeof window === "undefined") return () => {};+ window.addEventListener(LOCALE_DIRECTION_CHANGE_EVENT, listener);+ return () => window.removeEventListener(LOCALE_DIRECTION_CHANGE_EVENT, listener);+};++export const applyDocumentLocale = (locale: string): LocaleDirection => {+ const direction = i18n.dir(locale);+ if (typeof document === "undefined") return direction;++ const previousDirection = document.documentElement.getAttribute("dir");+ document.documentElement.lang = locale;+ document.documentElement.dir = direction;+ if (previousDirection !== direction && typeof window !== "undefined") {+ window.dispatchEvent(new Event(LOCALE_DIRECTION_CHANGE_EVENT));+ }+ return direction;+};const getStoredLocale = (): Locale | null => {try {@@ -95,8 +120,8 @@ export const getLocaleWithFallback = (userLocale?: string): Locale => {export const loadLocale = (locale: string): Locale => {const validLocale = isValidLocale(locale) ? (locale as Locale) : findNearestMatchedLanguage(navigator.language);setStoredLocale(validLocale);+ applyDocumentLocale(validLocale);i18n.changeLanguage(validLocale);- document.documentElement.lang = validLocale;return validLocale;};diff --git a/web/tests/column-grid.test.tsx b/web/tests/column-grid.test.tsxindex 629ee04f3..d0bd0e49c 100644--- a/web/tests/column-grid.test.tsx+++ b/web/tests/column-grid.test.tsx@@ -1,5 +1,6 @@+import { DirectionProvider } from "@base-ui/react/direction-provider";import { render } from "@testing-library/react";-import { describe, expect, it } from "vitest";+import { describe, expect, it, vi } from "vitest";import ColumnGrid from "@/components/ColumnGrid";// jsdom has no layout engine (offsetHeight/clientWidth are 0) and no ResizeObserver,@@ -41,4 +42,21 @@ describe("<ColumnGrid>", () => {expect(container.querySelectorAll('[data-testid="card"]')).toHaveLength(0);});++ it("places the first packed column at inline start in RTL", () => {+ const clientWidth = vi.spyOn(HTMLElement.prototype, "clientWidth", "get").mockReturnValue(532);+ const offsetHeight = vi.spyOn(HTMLElement.prototype, "offsetHeight", "get").mockReturnValue(100);++ const { getByTestId } = render(+ <DirectionProvider direction="rtl">+ <ColumnGrid items={[item("a"), item("b")]} getKey={getKey} renderItem={(i) => <div data-testid={`card-${i.id}`}>{i.id}</div>} />+ </DirectionProvider>,+ );++ expect(getByTestId("card-a").parentElement?.style.transform).toContain("translate3d(272px");+ expect(getByTestId("card-b").parentElement?.style.transform).toContain("translate3d(0px");++ clientWidth.mockRestore();+ offsetHeight.mockRestore();+ });});diff --git a/web/tests/dropdown-menu-size.test.tsx b/web/tests/dropdown-menu-size.test.tsxindex 49ff42914..1c2369b50 100644--- a/web/tests/dropdown-menu-size.test.tsx+++ b/web/tests/dropdown-menu-size.test.tsx@@ -1,6 +1,15 @@+import { DirectionProvider } from "@base-ui/react/direction-provider";import { fireEvent, render, screen } from "@testing-library/react";import { describe, expect, it } from "vitest";-import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";+import {+ DropdownMenu,+ DropdownMenuContent,+ DropdownMenuItem,+ DropdownMenuSub,+ DropdownMenuSubContent,+ DropdownMenuSubTrigger,+ DropdownMenuTrigger,+} from "@/components/ui/dropdown-menu";describe("DropdownMenu sizing", () => {it("applies compact content and item density through the sm size", async () => {@@ -25,4 +34,37 @@ describe("DropdownMenu sizing", () => {}expect(screen.getByRole("menuitem", { name: "Delete" })).toHaveAttribute("data-variant", "destructive");});++ it("opens submenus toward the inline end in RTL", async () => {+ render(+ <DirectionProvider direction="rtl">+ <DropdownMenu>+ <DropdownMenuTrigger>Actions</DropdownMenuTrigger>+ <DropdownMenuContent>+ <DropdownMenuSub>+ <DropdownMenuSubTrigger>More</DropdownMenuSubTrigger>+ <DropdownMenuSubContent>+ <DropdownMenuItem>Nested action</DropdownMenuItem>+ </DropdownMenuSubContent>+ </DropdownMenuSub>+ </DropdownMenuContent>+ </DropdownMenu>+ </DirectionProvider>,+ );++ fireEvent.click(screen.getByRole("button", { name: "Actions" }));+ const trigger = await screen.findByRole("menuitem", { name: "More" });+ expect(trigger.querySelector("svg")).toHaveClass("ms-auto", "rtl:rotate-180");++ trigger.focus();+ fireEvent.keyDown(trigger, { key: "ArrowLeft" });++ const nestedAction = await screen.findByRole("menuitem", { name: "Nested action" });+ const submenu = nestedAction.closest('[data-slot="dropdown-menu-content"]');+ expect(submenu).toHaveAttribute("data-side", "inline-end");+ expect(submenu).toHaveClass(+ "data-[side=inline-end]:data-starting-style:-translate-x-2",+ "rtl:data-[side=inline-end]:data-starting-style:translate-x-2",+ );+ });});diff --git a/web/tests/i18n-document-direction.test.ts b/web/tests/i18n-document-direction.test.tsnew file mode 100644index 000000000..b465ff705--- /dev/null+++ b/web/tests/i18n-document-direction.test.ts@@ -0,0 +1,47 @@+import { afterEach, describe, expect, it, vi } from "vitest";+import i18n from "@/i18n";+import { getLocaleDirection, loadLocale, subscribeToLocaleDirection } from "@/utils/i18n";++const originalLanguage = i18n.language;+const originalLangAttribute = document.documentElement.getAttribute("lang");+const originalDirAttribute = document.documentElement.getAttribute("dir");++const restoreAttribute = (name: "lang" | "dir", value: string | null) => {+ if (value === null) {+ document.documentElement.removeAttribute(name);+ } else {+ document.documentElement.setAttribute(name, value);+ }+};++describe("document locale direction", () => {+ afterEach(async () => {+ localStorage.clear();+ restoreAttribute("lang", originalLangAttribute);+ restoreAttribute("dir", originalDirAttribute);+ await i18n.changeLanguage(originalLanguage);+ });++ it.each([+ ["ar", "rtl"],+ ["fa", "rtl"],+ ["he", "rtl"],+ ["en", "ltr"],+ ] as const)("sets %s as a %s document", (locale, direction) => {+ loadLocale(locale);++ expect(document.documentElement).toHaveAttribute("lang", locale);+ expect(document.documentElement).toHaveAttribute("dir", direction);+ });++ it("notifies direction consumers before translations finish loading", () => {+ const listener = vi.fn();+ const unsubscribe = subscribeToLocaleDirection(listener);++ loadLocale("ar");++ expect(getLocaleDirection()).toBe("rtl");+ expect(listener).toHaveBeenCalledOnce();+ unsubscribe();+ });+});diff --git a/web/tests/memo-content-list.test.tsx b/web/tests/memo-content-list.test.tsxindex cb5addadf..86d6fdc77 100644--- a/web/tests/memo-content-list.test.tsx+++ b/web/tests/memo-content-list.test.tsx@@ -1,10 +1,10 @@import { renderToStaticMarkup } from "react-dom/server";import ReactMarkdown from "react-markdown";import remarkGfm from "remark-gfm";-import { List, ListItem } from "@/components/MemoContent/markdown";+import { describe, expect, it } from "vitest";import { TASK_LIST_CLASS, TASK_LIST_ITEM_CLASS } from "@/components/MemoContent/constants";+import { List, ListItem } from "@/components/MemoContent/markdown";import { remarkSplitMixedTaskLists } from "@/utils/remark-plugins/remark-split-mixed-task-lists";-import { describe, expect, it } from "vitest";const renderListContent = (content: string): string =>renderToStaticMarkup(@@ -27,9 +27,9 @@ describe("memo content lists", () => {expect(listOpenTags).toHaveLength(2);expect(listOpenTags[0]).toContain(TASK_LIST_CLASS);expect(listOpenTags[0]).toContain("list-none");- expect(listOpenTags[0]).not.toContain("pl-6");+ expect(listOpenTags[0]).not.toContain("ps-6");expect(listOpenTags[1]).not.toContain(TASK_LIST_CLASS);- expect(listOpenTags[1]).toContain("pl-6");+ expect(listOpenTags[1]).toContain("ps-6");expect(listOpenTags[1]).toContain("list-disc");expect(html).toContain('<li class="mt-0.5 leading-6">milk</li>');expect(html).not.toContain('<li class="mt-0.5 leading-6">\n<p>milk</p>');diff --git a/web/tests/memo-display-setting-menu.test.tsx b/web/tests/memo-display-setting-menu.test.tsxindex 4e70d19bb..643c59690 100644--- a/web/tests/memo-display-setting-menu.test.tsx+++ b/web/tests/memo-display-setting-menu.test.tsx@@ -1,3 +1,4 @@+import { DirectionProvider } from "@base-ui/react/direction-provider";import { fireEvent, render, screen } from "@testing-library/react";import { beforeEach, describe, expect, it, vi } from "vitest";import { SIDEBAR_SECTION_ACTION_BUTTON_CLASSES, SIDEBAR_SECTION_ACTION_ICON_CLASSES } from "@/components/AppSidebar/SidebarSection";@@ -58,4 +59,19 @@ describe("MemoDisplaySettingMenu", () => {expect(compactMode).toHaveAttribute("aria-disabled", "true");expect(screen.getByText("Grid layouts always use compact cards.")).toBeInTheDocument();});++ it("moves horizontally in the visual direction for RTL layouts", () => {+ render(+ <DirectionProvider direction="rtl">+ <ViewProvider>+ <MemoDisplaySettingMenu />+ </ViewProvider>+ </DirectionProvider>,+ );++ fireEvent.click(screen.getByRole("button", { name: "View options" }));+ fireEvent.keyDown(screen.getByRole("radiogroup", { name: "Layout" }), { key: "ArrowLeft" });++ expect(screen.getByRole("radio", { name: "2 columns" })).toBeChecked();+ });});diff --git a/web/tests/scroll-restoration.test.tsx b/web/tests/scroll-restoration.test.tsxindex 04636c352..436a7c19b 100644--- a/web/tests/scroll-restoration.test.tsx+++ b/web/tests/scroll-restoration.test.tsx@@ -1,7 +1,9 @@+import { useDirection } from "@base-ui/react/direction-provider";import { act, render, screen, waitFor } from "@testing-library/react";import { createMemoryRouter, RouterProvider } from "react-router-dom";import { beforeEach, describe, expect, it, vi } from "vitest";import App from "@/App";+import { useUserLocale } from "@/hooks/useUserLocale";vi.mock("@/contexts/InstanceContext", () => ({useInstance: () => ({@@ -20,6 +22,7 @@ describe("scroll restoration", () => {let scrollY = 0;beforeEach(() => {+ vi.mocked(useUserLocale).mockReturnValue("ltr");scrollY = 0;Object.defineProperty(window, "scrollY", {configurable: true,@@ -27,6 +30,25 @@ describe("scroll restoration", () => {});});+ it("provides the active locale direction to routed content", async () => {+ vi.mocked(useUserLocale).mockReturnValue("rtl");+ const DirectionProbe = () => <div>Direction: {useDirection()}</div>;+ const router = createMemoryRouter(+ [+ {+ path: "/",+ element: <App />,+ children: [{ index: true, element: <DirectionProbe /> }],+ },+ ],+ { initialEntries: ["/"] },+ );++ render(<RouterProvider router={router} />);++ expect(await screen.findByText("Direction: rtl")).toBeInTheDocument();+ });+it("resets new routes and restores history entries", async () => {const scrollTo = vi.spyOn(window, "scrollTo").mockImplementation((xOrOptions, y) => {scrollY = typeof xOrOptions === "number" ? (y ?? 0) : (xOrOptions.top ?? 0);diff --git a/web/tests/select.test.tsx b/web/tests/select.test.tsxindex ab991beb7..1937ccff0 100644--- a/web/tests/select.test.tsx+++ b/web/tests/select.test.tsx@@ -28,5 +28,9 @@ describe("Select", () => {const popup = document.querySelector('[data-slot="select-content"]');expect(popup).not.toBeNull();expect(popup?.parentElement).toHaveClass("isolate", "z-dropdown");++ const selectedOption = screen.getByRole("option", { name: "Last updated" });+ expect(selectedOption).toHaveClass("pe-8", "ps-2");+ expect(selectedOption.querySelector('[data-slot="select-item-indicator"]')).toHaveClass("end-2");});});diff --git a/web/tests/sidebar-resize-handle.test.tsx b/web/tests/sidebar-resize-handle.test.tsxindex 1705cc054..099158e12 100644--- a/web/tests/sidebar-resize-handle.test.tsx+++ b/web/tests/sidebar-resize-handle.test.tsx@@ -1,3 +1,4 @@+import { DirectionProvider } from "@base-ui/react/direction-provider";import { fireEvent, render, screen } from "@testing-library/react";import { type CSSProperties, useRef, useState } from "react";import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";@@ -18,25 +19,35 @@ vi.mock("@/utils/i18n", () => ({// handle writes to it. `railMounted` stands in for RootLayout's `md &&` gate, which unmounts the// rail — and with it the handle — when the window drops below the desktop breakpoint, while the// shell itself stays mounted.-const Harness = ({ onWidthChange = vi.fn(), railMounted = true }: { onWidthChange?: (width: number) => void; railMounted?: boolean }) => {+const Harness = ({+ onWidthChange = vi.fn(),+ railMounted = true,+ direction = "ltr",+}: {+ onWidthChange?: (width: number) => void;+ railMounted?: boolean;+ direction?: "ltr" | "rtl";+}) => {const targetRef = useRef<HTMLDivElement>(null);const [width, setWidth] = useState(SIDEBAR_DEFAULT_WIDTH);return (- <div ref={targetRef} data-testid="shell" style={{ [SIDEBAR_WIDTH_VAR]: `${width}px` } as CSSProperties}>- {railMounted && (- <SidebarResizeHandle- width={width}- minWidth={SIDEBAR_MIN_WIDTH}- maxWidth={SIDEBAR_MAX_WIDTH}- onWidthChange={(next) => {- setWidth(next);- onWidthChange(next);- }}- targetRef={targetRef}- />- )}- </div>+ <DirectionProvider direction={direction}>+ <div ref={targetRef} data-testid="shell" style={{ [SIDEBAR_WIDTH_VAR]: `${width}px` } as CSSProperties}>+ {railMounted && (+ <SidebarResizeHandle+ width={width}+ minWidth={SIDEBAR_MIN_WIDTH}+ maxWidth={SIDEBAR_MAX_WIDTH}+ onWidthChange={(next) => {+ setWidth(next);+ onWidthChange(next);+ }}+ targetRef={targetRef}+ />+ )}+ </div>+ </DirectionProvider>);};@@ -111,6 +122,21 @@ describe("<SidebarResizeHandle />", () => {expect(onWidthChange).toHaveBeenLastCalledWith(SIDEBAR_DEFAULT_WIDTH);});+ it("mirrors keyboard and pointer resizing for a right-hand RTL sidebar", () => {+ const onWidthChange = vi.fn();+ render(<Harness direction="rtl" onWidthChange={onWidthChange} />);+ const handle = screen.getByRole("separator");++ expect(handle).toHaveClass("-end-1");+ fireEvent.keyDown(handle, { key: "ArrowLeft" });+ expect(onWidthChange).toHaveBeenLastCalledWith(SIDEBAR_DEFAULT_WIDTH + 16);+ fireEvent.keyDown(handle, { key: "ArrowRight" });+ expect(onWidthChange).toHaveBeenLastCalledWith(SIDEBAR_DEFAULT_WIDTH);++ drag(SIDEBAR_DEFAULT_WIDTH, SIDEBAR_DEFAULT_WIDTH - 40);+ expect(shellWidthVar()).toBe(`${SIDEBAR_DEFAULT_WIDTH + 40}px`);+ });+it("jumps to each bound with Home and End", () => {const onWidthChange = vi.fn();render(<Harness onWidthChange={onWidthChange} />);diff --git a/web/tests/switch.test.tsx b/web/tests/switch.test.tsxnew file mode 100644index 000000000..4f32e0192--- /dev/null+++ b/web/tests/switch.test.tsx@@ -0,0 +1,16 @@+import { render, screen } from "@testing-library/react";+import { describe, expect, it } from "vitest";+import { Switch } from "@/components/ui/switch";++describe("Switch", () => {+ it("moves the checked thumb toward the inline end in both text directions", () => {+ render(<Switch aria-label="Example setting" defaultChecked />);++ const root = screen.getByRole("switch", { name: "Example setting" });+ const thumb = root.querySelector('[data-slot="switch-thumb"]');++ expect(root).toHaveAttribute("aria-checked", "true");+ expect(thumb).toHaveAttribute("data-checked");+ expect(thumb).toHaveClass("data-checked:translate-x-[calc(100%-2px)]", "rtl:data-checked:-translate-x-[calc(100%-2px)]");+ });+});diff --git a/web/tests/user-locale-direction.test.tsx b/web/tests/user-locale-direction.test.tsxnew file mode 100644index 000000000..c4fc09a86--- /dev/null+++ b/web/tests/user-locale-direction.test.tsx@@ -0,0 +1,39 @@+import { renderHook, waitFor } from "@testing-library/react";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";+import { useUserLocale } from "@/hooks/useUserLocale";+import i18n from "@/i18n";++vi.mock("@/contexts/AuthContext", () => ({+ useAuth: () => ({ userGeneralSetting: { locale: "ar" } }),+}));++const originalLanguage = i18n.language;+const originalLangAttribute = document.documentElement.getAttribute("lang");+const originalDirAttribute = document.documentElement.getAttribute("dir");++describe("useUserLocale", () => {+ beforeEach(async () => {+ localStorage.clear();+ localStorage.setItem("memos-locale", "en");+ document.documentElement.lang = "en";+ document.documentElement.dir = "ltr";+ await i18n.changeLanguage("en");+ });++ afterEach(async () => {+ localStorage.clear();+ if (originalLangAttribute === null) document.documentElement.removeAttribute("lang");+ else document.documentElement.lang = originalLangAttribute;+ if (originalDirAttribute === null) document.documentElement.removeAttribute("dir");+ else document.documentElement.dir = originalDirAttribute;+ await i18n.changeLanguage(originalLanguage);+ });++ it("keeps the user setting direction while its translations load", async () => {+ const { result } = renderHook(() => useUserLocale());++ await waitFor(() => expect(result.current).toBe("rtl"));+ expect(document.documentElement).toHaveAttribute("lang", "ar");+ expect(document.documentElement).toHaveAttribute("dir", "rtl");+ });+});