Skip to content

Fix borderFormatHandler to strip 'initial' color value#3350

Open
BryanValverdeU wants to merge 3 commits into
masterfrom
u/bvalverde/fixBorderBug
Open

Fix borderFormatHandler to strip 'initial' color value#3350
BryanValverdeU wants to merge 3 commits into
masterfrom
u/bvalverde/fixBorderBug

Conversation

@BryanValverdeU
Copy link
Copy Markdown
Contributor

@BryanValverdeU BryanValverdeU commented May 25, 2026

When the border color is 'initial', browsers ignore the change when setting it on the inline style of an element. Destructure the border value into [width, style, color] and replace 'initial' in the color position with an empty string before storing the format.

To Repro

Create an .html file with this content:

<table id="x_table_0" cellpadding="0" cellspacing="0" style="text-align:left; text-indent:0px; background-color:rgb(255,255,255); width:348px; color:rgb(51,51,51); box-sizing:border-box; border-collapse:collapse; border-spacing:0px"><tbody><tr><td style="text-align:center; text-indent:0px; border-width:1px 1px 3px; border-style:solid dotted double solid; border-color:initial; padding-top:1px; padding-right:1px; padding-left:1px; vertical-align:middle; width:113px; height:23px"><div class="x_elementToProof" style="text-align:center; text-indent:0px; margin:0px; font-family:&quot;맑은 고딕&quot;,monospace; font-size:11pt; color:rgb(51,51,51)">항목/업체</div></td><td style="text-align:center; text-indent:0px; border-width:1px 1px 3px; border-style:solid dotted double; border-color:initial; padding-top:1px; padding-right:1px; padding-left:1px; vertical-align:middle; width:115px"><div class="x_elementToProof" style="text-align:center; text-indent:0px; margin:0px; font-family:&quot;맑은 고딕&quot;,monospace; font-size:11pt; color:rgb(51,51,51)">SIGMA</div></td><td style="text-align:center; text-indent:0px; border-width:1px 1px 3px; border-style:solid solid double dotted; border-color:initial; padding-top:1px; padding-right:1px; padding-left:1px; vertical-align:middle; width:120px"><div class="x_elementToProof" style="text-align:center; text-indent:0px; margin:0px; font-family:&quot;맑은 고딕&quot;,monospace; font-size:11pt; color:rgb(51,51,51)">GIBSON</div></td></tr><tr><td style="text-align:center; text-indent:0px; border-right:1px dotted; border-bottom:1px dotted; border-left:1px solid; padding-top:1px; padding-right:1px; padding-left:1px; vertical-align:middle; width:113px; height:26px; box-sizing:border-box"><div class="x_elementToProof" style="text-align:center; text-indent:0px; margin:0px; font-family:&quot;맑은 고딕&quot;,monospace; font-size:11pt; color:rgb(51,51,51)">BROKERAGE</div></td><td style="text-align:right; text-indent:0px; border-right:1px dotted; border-bottom:1px dotted; padding-top:1px; padding-right:1px; padding-left:1px; vertical-align:middle; width:115px; height:26px; box-sizing:border-box"><div class="x_elementToProof" style="text-align:right; text-indent:0px; margin:0px; font-family:&quot;맑은 고딕&quot;,monospace; font-size:11pt; color:rgb(51,51,51)">$54,306.45</div></td><td style="text-align:right; text-indent:0px; border-right:1px solid; border-bottom:1px dotted; padding-top:1px; padding-right:1px; padding-left:1px; vertical-align:middle; width:120px; height:26px; box-sizing:border-box"><div class="x_elementToProof" style="text-align:right; text-indent:0px; margin:0px; font-family:&quot;맑은 고딕&quot;,monospace; font-size:11pt; color:rgb(51,51,51)">$54,306.45</div></td></tr><tr><td style="text-align:center; text-indent:0px; border-right:1px dotted; border-bottom:1px dotted; border-left:1px solid; padding-top:1px; padding-right:1px; padding-left:1px; vertical-align:middle; width:113px; height:22px"><div class="x_elementToProof" style="text-align:center; text-indent:0px; margin:0px; font-family:&quot;맑은 고딕&quot;,monospace; font-size:11pt; color:rgb(51,51,51)">VAT</div></td><td style="text-align:right; text-indent:0px; border-top:1px dotted; border-right:1px dotted; border-bottom:1px dotted; padding-top:1px; padding-right:1px; padding-left:1px; vertical-align:middle; width:115px"><div class="x_elementToProof" style="text-align:right; text-indent:0px; margin:0px; font-family:&quot;맑은 고딕&quot;,monospace; font-size:11pt; color:rgb(51,51,51)">$5,431</div></td><td style="text-align:right; text-indent:0px; border-top:1px dotted; border-right:1px solid; border-bottom:1px dotted; padding-top:1px; padding-right:1px; padding-left:1px; vertical-align:middle; width:120px"><div class="x_elementToProof" style="text-align:right; text-indent:0px; margin:0px; font-family:&quot;맑은 고딕&quot;,monospace; font-size:11pt; color:rgb(51,51,51)">$0.00</div></td></tr><tr><td style="text-align:center; text-indent:0px; border-right:1px dotted; border-bottom:1px solid; border-left:1px solid; background-color:rgb(208,208,208); padding-top:1px; padding-right:1px; padding-left:1px; vertical-align:middle; width:113px; height:22px"><div class="x_elementToProof" style="text-align:center; text-indent:0px; margin:0px; font-family:&quot;맑은 고딕&quot;,monospace; font-size:11pt; color:rgb(51,51,51)">TOTAL</div></td><td style="text-align:right; text-indent:0px; border-top:1px dotted; border-right:1px dotted; border-bottom:1px solid; background-color:rgb(208,208,208); padding-top:1px; padding-right:1px; padding-left:1px; vertical-align:middle; width:115px"><div class="x_elementToProof" style="text-align:right; text-indent:0px; margin:0px; font-family:&quot;맑은 고딕&quot;,monospace; font-size:11pt; color:rgb(51,51,51)">$59,737.09</div></td><td style="text-align:right; text-indent:0px; border-top:1px dotted; border-right:1px solid; border-bottom:1px solid; background-color:rgb(208,208,208); padding-top:1px; padding-right:1px; padding-left:1px; vertical-align:middle; width:120px"><div class="x_elementToProof" style="text-align:right; text-indent:0px; margin:0px; font-family:&quot;맑은 고딕&quot;,monospace; font-size:11pt; color:rgb(51,51,51)">&nbsp;$54,306.45</div></td></tr></tbody></table>

Open the HTML file in browser copy and paste to Rooster

Before
image

After
image

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 25, 2026

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://microsoft.github.io/roosterjs/pr-preview/pr-3350/

Built to branch gh-pages at 2026-05-25 23:59 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

When the border color is 'initial', browsers ignore the change when
setting it on the inline style of an element. Check the last part of
the border value and remove it if it is 'initial' before storing the
format. Uses the last element to handle cases where the border value
may not have all three parts (width, style, color).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a paste-formatting issue where border shorthands containing initial as the color (e.g. 1px solid initial) can be ignored by browsers when re-applied as inline styles, causing borders to be lost after paste. It updates borderFormatHandler to strip the trailing initial token from per-side border shorthand values before storing them in the model, and updates/extends tests to reflect and validate the corrected behavior.

Changes:

  • Strip trailing initial from per-side border shorthand strings during DOM→model parsing in borderFormatHandler.
  • Update Word Online paste expectations to no longer include initial in stored border strings.
  • Update/add paste and unit tests to validate border preservation and multi-value border-style shorthands.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
packages/roosterjs-content-model-plugins/test/paste/word/processPastedContentFromWacTest.ts Updates expected pasted table cell border strings to omit initial color.
packages/roosterjs-content-model-plugins/test/paste/e2e/cmPasteTest.ts Strengthens e2e expectations to ensure borders are preserved when border-color: initial is present.
packages/roosterjs-content-model-dom/test/formatHandlers/common/borderFormatHandlerTest.ts Adds coverage for multi-value border-style shorthand serialization across sides.
packages/roosterjs-content-model-dom/lib/formatHandlers/common/borderFormatHandler.ts Implements stripping of trailing initial from border shorthand values before storing format.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@BryanValverdeU BryanValverdeU force-pushed the u/bvalverde/fixBorderBug branch from 65299c1 to a0ab9ce Compare May 25, 2026 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants