Skip to content

RTL drawers and off-canvas panels

Position RTL drawers at the intended edge, match their slide direction, and test modal focus, closed states and mobile scrolling.

By , Founder of Ritla

Guide13 min read

A drawer can settle against the correct edge in Arabic and still animate from the wrong side. Its position follows a logical inset, but its motion still uses an English horizontal sign. Another version looks closed while its controls remain in the keyboard sequence, waiting outside the visible page.

Decide which edge the drawer belongs to, then make positioning, animation and interaction follow that decision. A navigation drawer at inline start normally moves from the left in English to the right in Arabic. A contextual inspector at inline end moves the other way. RTL does not mean that every panel opens on the right.

The example here is a sewing-pattern editor's piece inspector. On a compact screen, it opens as a modal drawer for the selected sleeve piece. It belongs at inline end: right in English, left in Arabic. The drawing canvas keeps its own geometric orientation; opening an Arabic inspector does not mirror the garment pattern.

Name the edge before choosing coordinates#

Use a placement option such as start or end when the component follows reading direction. Avoid names such as leftDrawer for a panel that is expected to change physical sides with locale.

Drawer placementLTR physical edgeRTL physical edgeMovement into the viewport
Inline startLeftRightFrom its outside edge toward the content
Inline endRightLeftFrom its outside edge toward the content
Bottom sheetBottomBottomUpward, unless the product defines another transition
Spatially attached panelDefined by its anchorDefined by its anchorFollows the anchor's spatial relationship

The inspector's inline-end placement is a product decision. A different editor might deliberately keep a measurement tool attached to the same physical side of its canvas. Record that exception in the placement model instead of scattering locale-specific overrides across its stylesheet.

Use an HTML dir attribute on the Arabic page or component. lang="ar" identifies Arabic content but does not establish the panel's layout direction. The drawer's text direction and its physical placement are related decisions, not interchangeable CSS declarations.

Before debugging an animation, disable it and inspect the open panel. Its intended viewport edge should be correct in both locales. If the resting position is wrong, changing the transform sign merely animates toward the wrong destination. Physical versus logical CSS explains how to translate the positioning intent into properties.

Choose modal behavior independently of appearance#

A panel shaped like a drawer can be modal or nonmodal. The narrow-screen inspector interrupts interaction with the canvas, so it needs modal behavior. A persistent desktop inspector can let users move between controls and the canvas without closing it.

Do not select aria-modal="true" because the panel has a backdrop-shaped shadow. Modality means that background interaction is blocked and keyboard focus stays inside the active dialog. Conversely, a visibly blocking overlay with an ordinary aside and no focus handling leaves keyboard users operating a canvas they cannot see.

For this compact inspector, a native dialog provides the modal foundation. Calling showModal() places it in the top layer and makes the rest of its document inert. A large z-index on an ordinary fixed panel does not provide that behavior.

Use a nonmodal component when the inspector is meant to remain available alongside the canvas. It should have a descriptive heading, a reachable close action and a predictable path back to the selected piece. Do not trap focus in that version. If a breakpoint changes the interaction model, treat that as a mode transition rather than only changing the width.

Give the closed drawer an actual closed state#

Here is the compact-screen inspector. The checkbox represents a local display preference; the host editor owns how that preference affects its drawing.

html
<button id="piece-inspector-open" type="button"        aria-haspopup="dialog" aria-controls="piece-inspector">  خصائص القطعة</button> <dialog id="piece-inspector" class="piece-drawer"        dir="rtl" lang="ar" aria-labelledby="piece-inspector-title">  <header class="piece-drawer__header">    <h2 id="piece-inspector-title" tabindex="-1">خصائص قطعة النمط</h2>    <button id="piece-inspector-close" type="button">إغلاق</button>  </header>  <div class="piece-drawer__body">    <p>القطعة: الكم الأمامي</p>    <label>      <input type="checkbox" checked>      إظهار خطوط القص    </label>  </div></dialog>

The dialog starts without open. Do not hide an otherwise open drawer only by moving its painted box outside the viewport. A transform changes where it is drawn; it does not by itself remove descendant controls from keyboard navigation or stop background interaction.

This controller opens and closes the native dialog. It moves initial focus to the heading, allowing the visitor to identify the selected inspector before reaching its preference control:

js
const pieceDrawer = document.getElementById('piece-inspector');const pieceOpener = document.getElementById('piece-inspector-open');const pieceCloser = document.getElementById('piece-inspector-close');const pieceTitle = document.getElementById('piece-inspector-title'); pieceOpener.addEventListener('click', () => {  if (pieceDrawer.open) return;  pieceDrawer.showModal();  pieceTitle.focus({ preventScroll: true });}); pieceCloser.addEventListener('click', () => {  pieceDrawer.close();});

The dialog element reference describes native closing and focus behavior. Keep the browser's Escape handling unless the product needs a specific dismissal policy. Verify that focus returns to the opener when it remains available. If selection changes remove that opener, the host needs a meaningful fallback in the editor.

Notice that there is no global rule setting every dialog to display: flex. Such a rule can defeat its closed presentation. Apply the drawer layout only to the open state, as the next example does. Test the unopened page with Tab before testing any animation.

Position the panel with logical insets#

The inspector needs a viewport-height shell with a scrollable body. Reset the dialog's default margins and size limits so its edge placement is deliberate:

css
.piece-drawer {  position: fixed;  inset-block: 0;  inset-inline-start: auto;  inset-inline-end: 0;  margin: 0;  inline-size: min(27rem, 100%);  max-inline-size: none;  block-size: 100dvh;  max-block-size: none;  box-sizing: border-box;  padding: 0;  border: 0;  overflow: hidden;}.piece-drawer[open] {  display: flex;  flex-direction: column;}.piece-drawer__header {  display: flex;  flex-shrink: 0;  align-items: start;  gap: 0.875rem;  padding: 1.25rem;}.piece-drawer__header h2 {  min-inline-size: 0;  margin: 0;}.piece-drawer__header button { margin-inline-start: auto; }.piece-drawer__body {  flex: 1;  min-block-size: 0;  overflow: auto;  padding: 1.25rem;}.piece-drawer::backdrop { background: rgb(18 24 30 / 42%); }

For this inline-end inspector, the physical positioning bug would be keeping right: 0 and left: auto in both locales. The logical pair above preserves that English placement while moving the Arabic inspector to the left. Remove the old physical declarations when replacing them; do not leave two competing sets of insets in different stylesheets.

The header's close action stays in normal flow. Its automatic inline-start margin consumes available space toward the end of the header row. A long Arabic heading can wrap rather than running beneath an absolutely positioned close button.

The logical end mapping is defined in MDN's inset-inline-end reference. In this horizontal writing mode, the zero inset attaches the inspector to the right in English and the left in Arabic.

If the product instead needs an inline-start navigation drawer, swap the logical anchors: start becomes zero and end becomes auto. That is a different placement variant, not an Arabic-only patch. Its entrance motion must change with it.

Match the motion to the anchored edge#

Logical positioning does not make translateX() logical. A positive x displacement still moves right, and a negative displacement still moves left. Changing dir does not reverse either sign.

For the inline-end inspector, a positive entrance displacement is appropriate in English because the panel's outside edge is on the right. In Arabic its outside edge is on the left, so that displacement must be negative.

Problem: this opening animation keeps the English displacement in Arabic.

css
.piece-drawer[open] { animation: piece-enter 190ms ease-out; }@keyframes piece-enter {  from { opacity: 0; transform: translateX(1.875rem); }  to { opacity: 1; transform: translateX(0); }}

The panel can finish in the correct location while appearing to move from the interior of the page rather than its outer edge. Inspect an intermediate frame; the final screenshot hides the mistake.

Better: replace that animation with a signed entry variable.

css
.piece-drawer { --piece-entry-x: 1.875rem; }.piece-drawer:dir(rtl) { --piece-entry-x: -1.875rem; }.piece-drawer[open] { animation: piece-enter 190ms ease-out; } @keyframes piece-enter {  from { opacity: 0; transform: translateX(var(--piece-entry-x)); }  to { opacity: 1; transform: translateX(0); }} @media (prefers-reduced-motion: reduce) {  .piece-drawer[open] { animation: none; }}

This is a short entrance, not a permanently offscreen closed position. Closing is immediate in this implementation. The closed dialog is absent from presentation, so the animation is not responsible for hiding interactive content. The reduced-motion media feature lets the entrance be removed while keeping that open-and-close behavior.

The physical transform and semantic :dir() behavior used here were measured in Chromium 151. CSS-only direction: rtl does not make :dir(rtl) match; use HTML direction. Repeat the motion test in supported browsers, including with reduced motion enabled.

A full edge-to-edge slide needs a displacement that clears the actual panel width and any visible shadow. If measuring that distance in JavaScript, measure the rendered panel after opening it, use the physical sign associated with its logical edge, and refresh the measurement after size changes. Do not assume an English fixed pixel width still matches a narrower Arabic drawer.

Keep exit animation from controlling modal cleanup#

If the product needs an animated exit, add an explicit closing phase. Calling close() immediately and then starting an ordinary opacity transition cannot keep a normally hidden dialog visible throughout that transition.

CSS can coordinate discrete display changes and top-layer removal, but those are additional mechanisms. MDN's starting-style documentation explains entrance starting values, while the overlay property covers retaining top-layer presentation during an exit transition. Test support for the complete technique you choose, not just support for transform.

With a JavaScript-driven exit, keep the modal open until its visual exit finishes, then close it and restore the interaction state. Element.animate() returns an animation, and its finished promise can coordinate that sequence. Reduced motion should take the immediate cleanup path.

Handle interruption too. Closing twice should not schedule two conflicting cleanups. Reopening during an old exit must invalidate that exit's eventual callback so it cannot close the newly opened inspector. An animation cancellation can reject its pending completion promise; account for that rejection rather than leaving a modal permanently in its closing phase.

Do not rely only on a hard-coded timeout copied from the stylesheet. It can disagree with reduced-motion rules, a changed duration or an interrupted transition. The application owns open, closing and closed states; the animation only determines when a visual transition has finished.

Test dismissal and focus as drawer behavior#

For the compact inspector, Tab and Shift+Tab should remain within the modal, Escape should dismiss according to the product's policy, and the close action should work without touching the backdrop. The WAI-ARIA modal dialog pattern describes these expectations and initial-focus choices.

Focus must be inside the drawer as it opens. Do not wait for a long entrance to finish before removing access to background controls. With the native example, modal behavior begins at showModal(); the short visual entrance follows that state change.

A backdrop is not automatically a dismissal policy. This example closes through its button or the browser's close request, not an invented click-away handler. If the product adds outside-pointer dismissal, distinguish a gesture that starts inside the panel and ends outside from a deliberate outside activation. Otherwise selecting text or dragging a control can dismiss the inspector accidentally.

If unsaved piece settings require confirmation, handle the dialog's cancel event and apply the same policy to every close route. Do not let Escape discard data while the visible close action asks for confirmation. Preserve a visible path to leave after any cancellation decision.

Test focus after the selected piece is deleted, the opener is filtered out, or the drawer is replaced by a desktop panel. Returning focus to a detached or hidden button does not return the visitor to their work. Choose the editor's next meaningful control in those cases.

Contain scrolling without hiding layout errors#

The drawer's body should scroll when its content exceeds the available height, while the header and close action remain reachable. The min-block-size: 0 on the flex child allows that body to shrink within the viewport-height shell. Test with the longest Arabic help text and with the software keyboard visible.

Use viewport-relative sizing as a starting point, then test browser chrome and keyboard changes on real phones. A dynamic viewport height does not remove the need to verify that a focused field and its error text can be reached. Safe-area padding may also be needed when controls approach a device edge.

If scrolling at the body's boundary should not chain into another scroll container, consider overscroll-behavior. That controls scroll chaining; it is not a complete document scroll-lock implementation. Verify background page position during wheel, touch and keyboard interaction.

For a custom overlay, keep scroll locking in a shared overlay manager if several components can open. Removing one drawer must not release a lock still needed by another modal. Restore previous styles and page position instead of blindly assigning a new global overflow value.

Do not add overflow-x: hidden to the entire page as the first response to a sideways scrollbar. It can conceal a misplaced drawer and clip unrelated content. Inspect the panel's actual bounds in both states. Fixing horizontal overflow in RTL covers finding the element that creates the excess width.

Preserve direction through portals and nested controls#

An overlay library may render the drawer under a document-level portal rather than beneath its trigger. The drawer then inherits direction from its actual DOM ancestors. A trigger inside a locally RTL editor does not automatically make a portaled panel RTL when the document remains LTR.

Set the library's direction option where required and put the intended dir and language on the rendered panel or its portal boundary. Inspect the resulting DOM rather than assuming the component tree establishes CSS inheritance. React's createPortal reference distinguishes physical DOM placement from React context and event behavior.

A native dialog entering the top layer is different: top-layer presentation does not itself reparent the element into a new DOM ancestor chain. Do not add portal-specific direction workarounds to the example merely because it appears above the page.

Check nested selects, tooltips and confirmation dialogs in their own rendered containers. A correct drawer can contain a menu that escaped to another portal and lost its direction. Also test whether that popup remains usable inside the active modal; positioning it above the backdrop is not enough if the modal system treats it as outside content.

Keep the sewing pattern's spatial values and any deliberate LTR notation scoped to their individual content. They should not force the entire inspector LTR or change the logical edge that anchors it.

Inspect the containing block when the edge still looks wrong#

A custom fixed drawer can have correct logical insets and still align with the editor canvas instead of the viewport. Pattern editors can transform a canvas ancestor for zooming or panning. That ancestor can establish the containing block for a fixed descendant, as described in MDN's position reference.

Inspect the ancestor chain when the drawer moves with a zoomed workspace or appears clipped to an editor frame. A higher stacking number cannot change the coordinate system used by its insets. Likewise, changing its transform sign cannot repair an anchor measured against the wrong box.

For a custom overlay, use an overlay host outside the transformed workspace, or choose a top-layer mechanism when its interaction model fits. Then check the new host's direction and styling assumptions. Moving a panel can resolve its containing-block problem while introducing the inheritance problem discussed above.

Do not remove the canvas's zoom transform merely to make the inspector align. Those are separate responsibilities. Test the drawer after zooming, panning and changing the selected piece so the placement is verified against the editor's actual layout.

Treat responsive changes as mode changes#

A persistent inspector and a modal drawer can share data and content, but their interaction rules differ. On a breakpoint change, decide whether to close the modal, present the desktop inspector and move focus to its corresponding control, or keep the modal until dismissal.

Do not leave the page inert after the panel becomes visually docked. Likewise, do not leave a desktop panel's background controls accessible after turning it into a blocking mobile overlay. Test resizing while focus is inside the checkbox, not only while the drawer is closed.

Keep the selected piece and draft settings outside the disposable presentation shell when they need to survive that change. Rendering separate mobile and desktop copies without coordinating their state can duplicate IDs, submit stale values or show controls for different pieces.

Change locale while the inspector is open too. The anchoring edge and its motion variables should update together. Avoid playing an old exit toward the English edge after the panel has already moved to its Arabic position. If direction changes during an animation, finish or cancel that transition before applying the new placement policy.

Verify closed, opening, open and closing states#

Start with the settled geometry. In Arabic, the inline-end inspector's left edge should meet the viewport's left edge; in English its right edge should meet the viewport's right edge. Check the direction actually computed on the panel, not just the page attribute.

Run this diagnostic with the native example open and its entrance finished:

js
const inspectedDrawer = document.getElementById('piece-inspector');if (!inspectedDrawer.open) throw new Error('Open the inspector first');const drawerBox = inspectedDrawer.getBoundingClientRect();console.table([{  direction: getComputedStyle(inspectedDrawer).direction,  left: drawerBox.left,  right: drawerBox.right,  width: drawerBox.width,  viewportWidth: document.documentElement.clientWidth}]);

Bounding rectangles are viewport-relative. On a desktop layout, this makes a misplaced edge visible without guessing from the shadow. Allow for fractional pixels. The closed native dialog has no rendered panel box to inspect; test its absence from interaction instead of treating a zero-width rectangle as an off-canvas position.

Then slow the entrance in browser animation tools. Verify that the panel moves from its outside edge toward its resting position and that text stays readable. Repeat with the longest title, reduced motion and a viewport narrow enough for the drawer to occupy the full width.

State or transitionWhat to inspect
Never openedDrawer controls are absent from Tab navigation
OpeningIntended edge and transform sign agree; background is unavailable for a modal
OpenClose action, internal scrolling and focus remain reachable
ClosingA delayed cleanup cannot leave a hidden modal blocking the page
Rapid close and reopenAn old exit cannot close the new opening
Locale changesText direction, anchor and animation policy remain consistent
Breakpoint changesModality, focus and selected-piece data match the new presentation

For custom off-canvas implementations, inspect document overflow and element bounds separately. The measured RTL document behavior is asymmetric: content past the left edge can create sideways scrolling, while content past the right edge can remain unreachable without that scrollbar. Scrollbar absence is therefore not proof that the panel's closed geometry is correct.

Finally, use the keyboard from the opener through the drawer and back to the editor. Confirm that a closed panel cannot intercept input, that cancellation preserves the intended settings, and that background scrolling returns to its prior state. Geometry tests alone cannot establish those lifecycle behaviors.

A free Ritla scan can check for translateX moving an element off-screen in RTL, R033, and document-level horizontal overflow, R040. For a panel attached to the wrong edge, continue with absolute positioning in RTL; for failures that appear only at phone width, see testing RTL across breakpoints.

Checks in this guide

See what your Arabic pages are hiding

Paste a URL. Ritla renders the page on desktop and mobile, runs every check, and shows the top issues with screenshot evidence.

Scan a page freeBrowse the checks