Skip to content

Commit c378f85

Browse files
2753 victoryarea events not triggering fill in docs (#2755)
1 parent 0b1d0dc commit c378f85

File tree

3 files changed

+78
-8
lines changed

3 files changed

+78
-8
lines changed

packages/victory-core/src/victory-util/events.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,13 @@ export function getScopedEvents(
165165
return "parent";
166166
}
167167
if (eventReturn.eventKey === "all") {
168-
return baseProps[childName]
169-
? without(keys(baseProps[childName]), "parent")
170-
: without(keys(baseProps), "parent");
168+
return newBaseProps[childName]
169+
? without(keys(newBaseProps[childName]), "parent")
170+
: without(keys(newBaseProps), "parent");
171171
} else if (eventReturn.eventKey === undefined && eventKey === "parent") {
172-
return baseProps[childName]
173-
? keys(baseProps[childName])
174-
: keys(baseProps);
172+
return newBaseProps[childName]
173+
? keys(newBaseProps[childName])
174+
: keys(newBaseProps);
175175
}
176176
return eventReturn.eventKey !== undefined
177177
? eventReturn.eventKey
@@ -195,7 +195,7 @@ export function getScopedEvents(
195195
);
196196
const mutatedProps = eventReturn.mutation(
197197
assign({}, mutationTargetProps, mutationTargetState),
198-
baseProps,
198+
newBaseProps,
199199
);
200200
const childState = baseState[childName] || {};
201201

@@ -238,7 +238,7 @@ export function getScopedEvents(
238238

239239
// returns an entire mutated state for all children
240240
const allChildNames =
241-
childNames === "all" ? without(keys(baseProps), "parent") : childNames;
241+
childNames === "all" ? without(keys(newBaseProps), "parent") : childNames;
242242
return Array.isArray(allChildNames)
243243
? allChildNames.reduce((memo, childName) => {
244244
return assign(memo, getReturnByChild(childName));

stories/victory-area.stories.tsx

+37
Original file line numberDiff line numberDiff line change
@@ -516,3 +516,40 @@ export const DisableInlineStyles = () => {
516516
</>
517517
);
518518
};
519+
520+
export const Events = () => {
521+
return (
522+
<div style={{ margin: 50 }}>
523+
<h3>Click Me</h3>
524+
<VictoryChart>
525+
<VictoryArea
526+
style={{
527+
data: { fill: "#c43a31" },
528+
}}
529+
events={[
530+
{
531+
target: "data",
532+
eventHandlers: {
533+
onClick: () => {
534+
return [
535+
{
536+
eventKey: "all",
537+
target: "data",
538+
mutation: (props) => {
539+
const fill = props.style && props.style.fill;
540+
return fill === "black"
541+
? null
542+
: { style: { fill: "black" } };
543+
},
544+
},
545+
];
546+
},
547+
},
548+
},
549+
]}
550+
data={getData(5)}
551+
/>
552+
</VictoryChart>
553+
</div>
554+
);
555+
};

stories/victory-line.stories.tsx

+33
Original file line numberDiff line numberDiff line change
@@ -508,3 +508,36 @@ export const DisableInlineStyles = () => {
508508
</>
509509
);
510510
};
511+
512+
export const Events = () => {
513+
return (
514+
<VictoryChart {...defaultChartProps}>
515+
<VictoryLine
516+
style={{
517+
data: { stroke: "#c43a31" },
518+
}}
519+
events={[
520+
{
521+
target: "parent",
522+
eventHandlers: {
523+
onClick: () => {
524+
return [
525+
{
526+
target: "data",
527+
eventKey: "all",
528+
mutation: ({ style }) => {
529+
return style.stroke === "black"
530+
? null
531+
: { style: { stroke: "black", strokeWidth: 5 } };
532+
},
533+
},
534+
];
535+
},
536+
},
537+
},
538+
]}
539+
data={getData(5, "seed-1")}
540+
/>
541+
</VictoryChart>
542+
);
543+
};

0 commit comments

Comments
 (0)