Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const BorderStyleKeyMap: {
borderLeft: 'border-left-style',
};

const DEFAULT_COLOR = '#000000';

/**
* @internal
*/
Expand All @@ -40,7 +42,8 @@ export const borderColorFormatHandler: FormatHandler<BorderFormat> = {
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(
Expand All @@ -67,6 +70,7 @@ export const borderColorFormatHandler: FormatHandler<BorderFormat> = {
const value = format[key];
if (value) {
const borderValues = extractBorderValues(value);
const borderColorProperty = BorderColorKeyMap[key];
if (borderValues.color) {
const transformedColor = adaptColor(
element,
Expand All @@ -76,7 +80,6 @@ export const borderColorFormatHandler: FormatHandler<BorderFormat> = {
context.darkColorHandler
);
if (transformedColor) {
const borderColorProperty = BorderColorKeyMap[key];
element.style.setProperty(borderColorProperty, transformedColor);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

The new "initial" parsing behavior is only covered in light mode. Adding a dark-mode test (with context.isDarkMode = true and a darkColorHandler present) would help catch regressions where the default black gets dropped/altered by getLightModeColor logic in dark mode.

Suggested change
});
});
it('Parse border with initial color in dark mode - should use default color', () => {
div.style.borderWidth = '1px';
div.style.borderStyle = 'solid';
div.style.borderTopColor = 'initial';
const mockDarkColorHandler = {
knownColors: {},
getDarkColor: jasmine.createSpy('getDarkColor').and.returnValue('#000000'),
updateKnownColor: jasmine.createSpy('updateKnownColor'),
generateColorKey: jasmine.createSpy('generateColorKey').and.returnValue('--colorKeyInitial'),
reset: jasmine.createSpy('reset'),
};
context.isDarkMode = true;
context.darkColorHandler = mockDarkColorHandler;
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',
true,
mockDarkColorHandler
);
expect(format.borderTop).toBe('1px solid #000000');
});

Copilot uses AI. Check for mistakes.
});

describe('borderColorFormatHandler.apply', () => {
Expand Down
Loading