mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-20 19:16:08 +00:00
fix(mobile): Arabic reads in its direction: arrows turn round, Latin names keep their ends, figures stay whole
In the touch shell the back, forward, disclosure, date-range and flow arrows kept pointing right in Arabic, so Settle up showed the debt the wrong way round and Vacay's year arrows pointed inward. The shell now mirrors lucide's direction arrows in right-to-left languages; an icon that names its own treatment keeps it, and the lightbox arrows stay on their physical sides. Latin user text in Arabic rows lost its beginning when cut and moved its punctuation to the wrong end. Names, titles, addresses and file names take their direction from their own text (dir=auto) and still line up with the row; markdown paragraphs, chat messages, poll options and journal stories are isolated; signed balances, amounts, sizes, rates and leg figures read as one left-to-right run; URL fields read left to right. Name pairs joined by an arrow isolate each name and point from the first to the second. The hero progress and poll result bars fill from the start edge. Arabic and Hebrew uppercase caption labels grow a step and take the muted ink, and a todo's due date in a notification is written in the reader's language instead of as YYYY-MM-DD.
This commit is contained in:
@@ -41,4 +41,23 @@ describe('MarkdownText', () => {
|
||||
expect(wrapper.className).toContain('truncate')
|
||||
expect(wrapper.className).toContain('text-m-muted')
|
||||
})
|
||||
|
||||
it('FE-MDTEXT-007: a clamped row takes its direction from its own text, so a Latin address in Arabic is cut at its end', () => {
|
||||
const { container } = render(<MarkdownText clamp>{'68 Fukakusa Yabunouchicho, Fushimi Ward, Kyoto'}</MarkdownText>)
|
||||
const wrapper = container.firstElementChild as HTMLElement
|
||||
expect(wrapper).toHaveAttribute('dir', 'auto')
|
||||
expect(wrapper).toHaveClass('truncate')
|
||||
// No isolate inside: dir="auto" would not see the text through a <bdi>.
|
||||
expect(wrapper.querySelector('bdi')).toBeNull()
|
||||
})
|
||||
|
||||
it('FE-MDTEXT-008: in a full view each paragraph runs in its own direction, inside its block', () => {
|
||||
const text = ["Kyoto's kitchen: pickles and matcha everything.", 'Second paragraph?'].join('\n\n')
|
||||
const { container } = render(<MarkdownText>{text}</MarkdownText>)
|
||||
expect(container.firstElementChild).not.toHaveAttribute('dir')
|
||||
const paragraphs = container.querySelectorAll('p')
|
||||
expect(paragraphs).toHaveLength(2)
|
||||
paragraphs.forEach(p => expect(p.firstElementChild?.tagName).toBe('BDI'))
|
||||
expect(paragraphs[1].textContent).toBe('Second paragraph?')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { Components } from 'react-markdown'
|
||||
import remarkGfm from 'remark-gfm'
|
||||
import remarkBreaks from 'remark-breaks'
|
||||
import { markdownLinkComponents } from './markdownLink'
|
||||
import { isolatedTextBlocks } from './markdownSanitize'
|
||||
|
||||
/**
|
||||
* A clamped caption lives inside a tappable row, so an anchor there would eat
|
||||
@@ -12,6 +13,8 @@ const clampedComponents: Components = {
|
||||
a: ({ children }) => <>{children}</>,
|
||||
}
|
||||
|
||||
const fullComponents: Components = { ...isolatedTextBlocks, ...markdownLinkComponents }
|
||||
|
||||
/**
|
||||
* A description or note, rendered (#2337). The field is Markdown wherever it is
|
||||
* written — the editors ship a formatting bar — so printing it raw anywhere
|
||||
@@ -20,6 +23,9 @@ const clampedComponents: Components = {
|
||||
* `clamp` is the list-row variant: one line high, matching what the desktop
|
||||
* sidebar rows do with the same field. The height cap is inline because the row
|
||||
* itself sets a font size, and a Tailwind `leading-*` would race with it.
|
||||
* The clamped line takes its direction from its own text (dir="auto" on the
|
||||
* row, which a <bdi> inside would hide from it), so a Latin address in an Arabic
|
||||
* row loses its end at the cut, not its beginning.
|
||||
*/
|
||||
export default function MarkdownText({ children, className = '', clamp = false }: {
|
||||
children: string
|
||||
@@ -28,12 +34,13 @@ export default function MarkdownText({ children, className = '', clamp = false }
|
||||
}) {
|
||||
return (
|
||||
<div
|
||||
dir={clamp ? 'auto' : undefined}
|
||||
className={`collab-note-md ${clamp ? 'truncate ' : ''}${className}`}
|
||||
style={clamp ? { maxHeight: '1.2em', lineHeight: 1.2 } : undefined}
|
||||
>
|
||||
<Markdown
|
||||
remarkPlugins={[remarkGfm, remarkBreaks]}
|
||||
components={clamp ? clampedComponents : markdownLinkComponents}
|
||||
components={clamp ? clampedComponents : fullComponents}
|
||||
>
|
||||
{children}
|
||||
</Markdown>
|
||||
|
||||
@@ -31,6 +31,35 @@ export const sanitizedMarkdownPlugins: NonNullable<Options['rehypePlugins']> = [
|
||||
[rehypeSanitize, schema],
|
||||
]
|
||||
|
||||
/**
|
||||
* A paragraph or heading of user text runs in its own direction: a Latin note
|
||||
* in the Arabic UI keeps its question mark and full stop at its end (and an
|
||||
* Arabic one in an English UI), while the block keeps the alignment of the page
|
||||
* around it. The isolate is inline, so the block itself stays as it was.
|
||||
*/
|
||||
export const isolatedTextBlocks: Components = {
|
||||
p: ({ children }) => (
|
||||
<p>
|
||||
<bdi>{children}</bdi>
|
||||
</p>
|
||||
),
|
||||
h1: ({ children }) => (
|
||||
<h1>
|
||||
<bdi>{children}</bdi>
|
||||
</h1>
|
||||
),
|
||||
h2: ({ children }) => (
|
||||
<h2>
|
||||
<bdi>{children}</bdi>
|
||||
</h2>
|
||||
),
|
||||
h3: ({ children }) => (
|
||||
<h3>
|
||||
<bdi>{children}</bdi>
|
||||
</h3>
|
||||
),
|
||||
}
|
||||
|
||||
/**
|
||||
* Links as in markdownLinkComponents (#1629): own tab plus `rel` protection.
|
||||
* The exception is a footnote or heading link, which points inside the text
|
||||
@@ -38,6 +67,7 @@ export const sanitizedMarkdownPlugins: NonNullable<Options['rehypePlugins']> = [
|
||||
* somewhere else.
|
||||
*/
|
||||
export const sanitizedMarkdownComponents: Components = {
|
||||
...isolatedTextBlocks,
|
||||
a: ({ children, href, ...rest }) =>
|
||||
href?.startsWith('#') ? (
|
||||
<a {...rest} href={href}>
|
||||
|
||||
Reference in New Issue
Block a user