Skip to content

Commit 9068bda

Browse files
authored
fix(richtext-lexical): add container div to table element to allow horizontal scroll in HTML and JSX converters (#11119)
### What? Add a `div` wrapper to `table` tag in `TableFeature` ### Why? This allows for adding horizontal scrolling to the table. We use table in our blog, however, on mobile, the content is wider than the screen width, and causes a horizontal scroll of all the content. I attached a video to show. You can see it by visiting the page on mobile https://magichour.ai/blog/10-best-ai-video-generators https://github.com/user-attachments/assets/55778765-697e-426d-ac8a-1b0913adac13 Adding this container div allow me to target the div with a style ```css .lexical-table-container { overflow-x: scroll; } ``` ### How? ![Screenshot 2025-02-11 at 11 26 18 AM](https://github.com/user-attachments/assets/873050b3-79b9-49ec-85ed-297286813577) I tested this change by manually editing the HTML in our blog to include the `div` with the overflow style, and it fixes the issue. Also, verified just adding the `div` did not change anything related to the rendered output.
1 parent 155f9f8 commit 9068bda

File tree

2 files changed

+6
-4
lines changed
  • packages/richtext-lexical/src
    • exports/react/components/RichText/converter/converters
    • features/experimental_table/server

2 files changed

+6
-4
lines changed

packages/richtext-lexical/src/exports/react/components/RichText/converter/converters/table.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ export const TableJSXConverter: JSXConverters<
1313
nodes: node.children,
1414
})
1515
return (
16-
<table className="lexical-table" style={{ borderCollapse: 'collapse' }}>
17-
<tbody>{children}</tbody>
18-
</table>
16+
<div className="lexical-table-container">
17+
<table className="lexical-table" style={{ borderCollapse: 'collapse' }}>
18+
<tbody>{children}</tbody>
19+
</table>
20+
</div>
1921
)
2022
},
2123
tablecell: ({ node, nodesToJSX }) => {

packages/richtext-lexical/src/features/experimental_table/server/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export const EXPERIMENTAL_TableFeature = createServerFeature({
101101
req,
102102
showHiddenFields,
103103
})
104-
return `<table class="lexical-table" style="border-collapse: collapse;">${childrenText}</table>`
104+
return `<div class="lexical-table-container"><table class="lexical-table" style="border-collapse: collapse;">${childrenText}</table></div>`
105105
},
106106
nodeTypes: [TableNode.getType()],
107107
},

0 commit comments

Comments
 (0)