Skip to content

Commit 808ffef

Browse files
authored
Merge pull request #1743 from FormidableLabs/improvement/container-role-prop
allow user provided roles for VictoryContainer
2 parents 0d52728 + ff797a2 commit 808ffef

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

packages/victory-core/src/index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ export interface VictoryContainerProps {
256256
portalZIndex?: number;
257257
preserveAspectRatio?: string;
258258
responsive?: boolean;
259+
role?: string;
259260
style?: React.CSSProperties;
260261
tabIndex?: number;
261262
theme?: VictoryThemeDefinition;

packages/victory-core/src/victory-container/victory-container.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export default class VictoryContainer extends React.Component {
3333
portalZIndex: CustomPropTypes.integer,
3434
preserveAspectRatio: PropTypes.string,
3535
responsive: PropTypes.bool,
36+
role: PropTypes.string,
3637
style: PropTypes.object,
3738
tabIndex: PropTypes.number,
3839
theme: PropTypes.object,
@@ -44,7 +45,8 @@ export default class VictoryContainer extends React.Component {
4445
className: "VictoryContainer",
4546
portalComponent: <Portal />,
4647
portalZIndex: 99,
47-
responsive: true
48+
responsive: true,
49+
role: "img"
4850
};
4951

5052
static contextType = TimerContext;
@@ -178,7 +180,8 @@ export default class VictoryContainer extends React.Component {
178180
title,
179181
desc,
180182
tabIndex,
181-
preserveAspectRatio
183+
preserveAspectRatio,
184+
role
182185
} = this.props;
183186
const style = responsive
184187
? this.props.style
@@ -188,7 +191,7 @@ export default class VictoryContainer extends React.Component {
188191
width,
189192
height,
190193
tabIndex,
191-
role: "img",
194+
role,
192195
"aria-labelledby":
193196
[title && this.getIdForElement("title"), this.props["aria-labelledby"]]
194197
.filter(Boolean)

test/client/spec/victory-core/victory-container/victory-container.spec.js

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ describe("components/victory-container", () => {
1616
expect(output.prop("role")).to.contain("img");
1717
});
1818

19+
it("renders an svg with a custom role", () => {
20+
const wrapper = shallow(<VictoryContainer role="presentation" />);
21+
const output = wrapper.find("svg").at(0);
22+
expect(output.prop("role")).to.contain("presentation");
23+
});
24+
1925
it("renders an svg with a title node", () => {
2026
const wrapper = shallow(<VictoryContainer title="Victory Chart" />);
2127
const output = wrapper.find("title");

0 commit comments

Comments
 (0)