Skip to content

Commit

Permalink
feat: support experimental RTL mode for ol and ul elements
Browse files Browse the repository at this point in the history
Set `enableExperimentalRtl` to `true` in props for the OL and UL element
renderers. When this value is true, and the `direction` CSS property is
set to `'rtl'`, **or** the `dir` attribute is set to `'rtl'` for this
element or one of its parent, the list marker will be flushed to the
right.
  • Loading branch information
jsamr committed Apr 16, 2021
1 parent 0f87b22 commit 0954d8b
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/render-html/src/elements/ListElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ export interface ListElementProps<T extends 'ol' | 'ul'>
listType: T;
getListStyleTypeFromNestLevel: (nestLevel: number) => SupportedListStyleType;
getStyleFromNestLevel?: (nestLevel: number) => ViewStyle | null;
/**
* If `true`:
* - lists markers will be flushed to the right when `I18nManager.isRtl` is `false`.
* - list markers prefixes and suffixes print order will be reversed.
*
* @remarks Beware that left and right padding of li elements *will not*
* be switched.
*/
enableExperimentalRtl?: boolean;
}

function getStartIndex(tnode: TNode) {
Expand Down Expand Up @@ -88,14 +97,16 @@ export default function ListElement({
getListStyleTypeFromNestLevel,
getStyleFromNestLevel,
markers,
enableExperimentalRtl = false,
...props
}: ListElementProps<any>) {
const nestLevel =
listType === 'ol' ? markers.olNestLevel : markers.ulNestLevel;
const TChildrenRenderer = useTChildrenRenderer();
const rtl =
tnode.styles.nativeBlockFlow.direction === 'rtl' ||
markers.direction === 'rtl';
enableExperimentalRtl &&
(tnode.styles.nativeBlockFlow.direction === 'rtl' ||
markers.direction === 'rtl');
const nestLevelStyle = getStyleFromNestLevel?.call(null, nestLevel);
const selectedListType = getListStyleTypeFromNestLevel(nestLevel);
const listStyleType =
Expand Down

0 comments on commit 0954d8b

Please sign in to comment.