Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/components/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ type MenuItemBaseProps = ForwardedFSClassProps &
/** The type of brick road indicator to show. */
brickRoadIndicator?: ValueOf<typeof CONST.BRICK_ROAD_INDICATOR_STATUS>;

/** Should render the content in HTML format */
/** Should render the content in HTML format. A title without HTML content is rendered as plain text even when this is set. */
shouldRenderAsHTML?: boolean;

/** Whether or not the text should be escaped */
Comment thread
jmgraa marked this conversation as resolved.
Expand Down Expand Up @@ -752,6 +752,8 @@ function MenuItem({
return Parser.replace(helperText, {shouldEscapeText});
}, [helperText, shouldParseHelperText, shouldEscapeText]);

const shouldRenderTitleAsHTML = shouldRenderAsHTML && !!title && Parser.isHTML(title);

const processedTitle = useMemo(() => {
let titleToWrap = '';
if (shouldRenderAsHTML) {
Expand Down Expand Up @@ -1050,7 +1052,14 @@ function MenuItem({
>
{!!title && (shouldRenderAsHTML || (shouldParseTitle && !!html.length)) && (
<View style={[styles.renderHTMLTitle, styles.textAlignLeft, shouldApplyIconPaddingToHTMLTitle && iconLeftPadding]}>
<RenderHTML html={processedTitle} />
{/* Use Text instead of RenderHTML when the title is plain text.
Titles with shouldRenderAsHTML use baseFontStyle, which differs from combinedTitleTextStyle below.
*/}
{shouldRenderTitleAsHTML || shouldParseTitle ? (
<RenderHTML html={processedTitle} />
) : (
<Text style={styles.webViewStyles.baseFontStyle}>{convertToLTR(Parser.htmlToText(processedTitle))}</Text>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary htmlToText round-trip on plain text

When shouldRenderTitleAsHTML is false, processedTitle wraps the title in <comment> tags only for Parser.htmlToText to strip them. Could this just use convertToLTR(title ?? '') directly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wrap-then-strip pattern looks redundant. However, it exists because the processedTitle logic always appends , regardless of whether the output is HTML or plain text. If we remove Parser.htmlToText, the user will see literal "" tags in the text.

The truncation logic in processedTitle is awkward, but refactoring it is out of scope for this PR, so we retain the existing pipeline.

)}
Comment thread
jmgraa marked this conversation as resolved.
</View>
)}
{!shouldRenderAsHTML && !shouldParseTitle && !!title && (
Expand Down
Loading