Skip to content

Commit e3724ff

Browse files
authored
[react] Exclude SVG elements from CSS reset (#1252)
1 parent 4b78468 commit e3724ff

3 files changed

Lines changed: 42 additions & 1 deletion

File tree

renderers/react/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## Unreleased
22

3+
- (v0_8) Exclude SVG elements and descendants from CSS reset to restore SVG rendering. [#1252](https://github.com/google/A2UI/pull/1252)
4+
35
- **BREAKING CHANGE**: Renamed `createReactComponent` to `createComponentImplementation`.
46
- **BREAKING CHANGE**: Renamed `createBinderlessComponent` to `createBinderlessComponentImplementation`.
57
- **BREAKING CHANGE**: Removed `minimalCatalog`.

renderers/react/src/v0_8/styles/reset.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
*/
3333
export const resetStyles: string = `
3434
@layer a2ui-reset {
35-
:where(.a2ui-surface) :where(*) {
35+
:where(.a2ui-surface) :where(*:not(svg, svg *:not(foreignObject *))) {
3636
all: revert;
3737
}
3838
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Copyright 2026 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
import {describe, it, expect} from 'vitest';
17+
import {render} from '@testing-library/react';
18+
import React from 'react';
19+
import {A2UIProvider} from '../../../../src/v0_8';
20+
import {resetStyles} from '../../../../src/v0_8/styles/reset';
21+
describe('SVG Reset Exclusion', () => {
22+
it('should have the correct CSS selector in resetStyles', () => {
23+
expect(resetStyles).toContain(':not(svg, svg *:not(foreignObject *))');
24+
});
25+
it('should allow presentational attributes on SVG elements', () => {
26+
const {container} = render(
27+
<A2UIProvider>
28+
<div className="a2ui-surface">
29+
<svg fill="red" data-testid="test-svg" width="100" height="100">
30+
<circle cx="50" cy="50" r="40" />
31+
</svg>
32+
</div>
33+
</A2UIProvider>,
34+
);
35+
const svg = container.querySelector('svg');
36+
expect(svg).toBeInTheDocument();
37+
expect(svg).toHaveAttribute('fill', 'red');
38+
});
39+
});

0 commit comments

Comments
 (0)