diff --git a/packages/roosterjs-content-model-dom/lib/formatHandlers/common/borderColorFormatHandler.ts b/packages/roosterjs-content-model-dom/lib/formatHandlers/common/borderColorFormatHandler.ts index 0ef75b219d3..40c9c3c1ee2 100644 --- a/packages/roosterjs-content-model-dom/lib/formatHandlers/common/borderColorFormatHandler.ts +++ b/packages/roosterjs-content-model-dom/lib/formatHandlers/common/borderColorFormatHandler.ts @@ -28,6 +28,8 @@ const BorderStyleKeyMap: { borderLeft: 'border-left-style', }; +const DEFAULT_COLOR = '#000000'; + /** * @internal */ @@ -40,7 +42,8 @@ export const borderColorFormatHandler: FormatHandler = { BorderKeys.forEach(key => { const width = element.style.getPropertyValue(BorderWidthKeyMap[key]); const style = element.style.getPropertyValue(BorderStyleKeyMap[key]); - const borderColor = retrieveElementColor(element, key); + const color = retrieveElementColor(element, key); + const borderColor = color == 'initial' ? DEFAULT_COLOR : color; if (borderColor) { const lightModeColor = getLightModeColor( @@ -67,6 +70,7 @@ export const borderColorFormatHandler: FormatHandler = { const value = format[key]; if (value) { const borderValues = extractBorderValues(value); + const borderColorProperty = BorderColorKeyMap[key]; if (borderValues.color) { const transformedColor = adaptColor( element, @@ -76,7 +80,6 @@ export const borderColorFormatHandler: FormatHandler = { context.darkColorHandler ); if (transformedColor) { - const borderColorProperty = BorderColorKeyMap[key]; element.style.setProperty(borderColorProperty, transformedColor); } } diff --git a/packages/roosterjs-content-model-dom/test/formatHandlers/common/borderColorFormatHandlerTest.ts b/packages/roosterjs-content-model-dom/test/formatHandlers/common/borderColorFormatHandlerTest.ts index e254325dbfc..1a9eba8116b 100644 --- a/packages/roosterjs-content-model-dom/test/formatHandlers/common/borderColorFormatHandlerTest.ts +++ b/packages/roosterjs-content-model-dom/test/formatHandlers/common/borderColorFormatHandlerTest.ts @@ -190,6 +190,24 @@ describe('borderColorFormatHandler.parse', () => { ); expect(format.borderTop).toBe('1px solid red'); }); + + it('Parse border with initial color - should use default color', () => { + div.style.borderWidth = '1px'; + div.style.borderStyle = 'solid'; + div.style.borderTopColor = 'initial'; + + context.isDarkMode = false; + context.darkColorHandler = undefined; + + spyOn(colorUtils, 'retrieveElementColor').and.returnValue('initial'); + spyOn(colorUtils, 'getLightModeColor').and.returnValue('#000000'); + + borderColorFormatHandler.parse(format, div, context, {}); + + expect(colorUtils.retrieveElementColor).toHaveBeenCalledWith(div, 'borderTop'); + expect(colorUtils.getLightModeColor).toHaveBeenCalledWith('#000000', false, undefined); + expect(format.borderTop).toBe('1px solid #000000'); + }); }); describe('borderColorFormatHandler.apply', () => {