-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat: add dir="auto" and text-align: justify for RTL support #2823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,7 +26,7 @@ export class ErrorBoundary extends React.Component< | |
| <ErrorWrapper> | ||
| <h1>Something went wrong...</h1> | ||
| <small> {this.state.error.message} </small> | ||
| <p> | ||
| <p dir="auto"> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor, and easy to miss: this
|
||
| <details> | ||
| <summary>Stack trace</summary> | ||
| <pre>{this.state.error.stack}</pre> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,13 @@ import styled from 'styled-components'; | |
| // Workaround for DOMPurify type issues (https://github.com/cure53/DOMPurify/issues/1034) | ||
| const dompurify = DOMPurify['default'] as DOMPurify.DOMPurify; | ||
|
|
||
| // Add dir="auto" to p and h2 elements for RTL support | ||
| dompurify.addHook('afterSanitizeAttributes', (node) => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the cause of the 14 suite failures, and I think it needs a different home regardless. It throws at import time. Line 10 above is Because almost everything imports It is a global side effect. It only runs when All three go away if you set the attribute during markdown rendering instead. In const renderParagraph = renderer.paragraph.bind(renderer);
renderer.paragraph = (...args) => renderParagraph(...args).replace('<p>', '<p dir="auto">');(or override |
||
| if (node.tagName === 'P' || node.tagName === 'H2') { | ||
| node.setAttribute('dir', 'auto'); | ||
| } | ||
| }); | ||
|
|
||
| const StyledMarkdownSpan = styled(StyledMarkdownBlock)` | ||
| display: inline; | ||
| `; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,8 @@ export const StyledMarkdownBlock = styled( | |
| line-height: ${props => props.theme.typography.lineHeight}; | ||
|
|
||
| p { | ||
| text-align: justify; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same point as on Redoc's middle panel is narrow, and justified text in a narrow measure produces uneven word spacing and vertical rivers of whitespace. WCAG 1.4.8 explicitly advises against justified blocks of text because that irregular spacing is harder to track for readers with dyslexia and some low-vision conditions — which cuts against the spirit of the change. Since this is applied to all users regardless of language, it is a global typographic change rather than RTL support. |
||
|
|
||
| &:last-child { | ||
| margin-bottom: 0; | ||
| } | ||
|
|
@@ -63,6 +65,7 @@ export const StyledMarkdownBlock = styled( | |
| h2 { | ||
| ${headerCommonMixin(2)}; | ||
| color: ${props => props.theme.colors.text.primary}; | ||
| text-align: justify; | ||
| } | ||
|
|
||
| code { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ export const SearchWrap = styled.div` | |
|
|
||
| export const SearchInput = styled.input.attrs(() => ({ | ||
| className: 'search-input', | ||
| dir: 'auto', | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one is just nice — no notes. An RTL user typing into the search field gets the caret and text alignment they expect, it costs one line, and there is no effect on LTR users. If the PR were trimmed down to only the |
||
| }))` | ||
| width: calc(100% - ${props => props.theme.spacing.unit * 8}px); | ||
| box-sizing: border-box; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
dir: 'auto'on line 23 is good. Thistext-align: justifyI would drop, along with its twin onH3and the two inMarkdown/styled.elements.tsx.Justification is orthogonal to direction —
diralready solves RTL. This line changes heading alignment for every Redoc deployment, LTR included, as a side effect of an RTL PR. On headings specifically it does nothing in the usual single-line case and stretches wrapped headings unevenly.If the intent is alignment that follows the text direction, the logical property does it properly and is a no-op for existing LTR users:
Either way I would move alignment into its own PR — it is a visual/typographic decision maintainers will want to weigh separately, and it would be a shame to have it hold up the
dir="auto"work, which is much less contentious.