diff --git a/src/victory-tooltip/victory-tooltip.js b/src/victory-tooltip/victory-tooltip.js index f16db37..60053d4 100644 --- a/src/victory-tooltip/victory-tooltip.js +++ b/src/victory-tooltip/victory-tooltip.js @@ -94,55 +94,45 @@ export default class VictoryTooltip extends React.Component { groupComponent: }; - static defaultEvents = [{ - target: "data", - eventHandlers: { - onMouseOver: (targetProps) => { - return [ - { - target: "labels", - mutation: () => ({ active: true }) - }, { - target: "data", - mutation: () => targetProps.activateData ? ({ active: true }) : ({ active: undefined }) - } - ]; - }, - onTouchStart: (targetProps) => { - return [ - { - target: "labels", - mutation: () => ({ active: true }) - }, { - target: "data", - mutation: () => targetProps.activateData ? ({ active: true }) : ({ active: undefined }) - } - ]; - }, - onMouseOut: () => { - return [ - { - target: "labels", - mutation: () => ({ active: undefined }) - }, { - target: "data", - mutation: () => ({ active: undefined }) - } - ]; - }, - onTouchEnd: () => { - return [ - { - target: "labels", - mutation: () => ({ active: undefined }) - }, { - target: "data", - mutation: () => ({ active: undefined }) - } - ]; + static defaultEvents = (props) => { + return [{ + target: "data", + eventHandlers: { + onMouseOver: () => { + return props.activateData ? + [ + { target: "labels", mutation: () => ({ active: true }) }, + { target: "data", mutation: () => ({ active: true }) } + ] : + [{ target: "labels", mutation: () => ({ active: true }) }]; + }, + onTouchStart: () => { + return props.activateData ? + [ + { target: "labels", mutation: () => ({ active: true }) }, + { target: "data", mutation: () => ({ active: true }) } + ] : + [{ target: "labels", mutation: () => ({ active: true }) }]; + }, + onMouseOut: () => { + return props.activateData ? + [ + { target: "labels", mutation: () => ({ active: false }) }, + { target: "data", mutation: () => ({ active: false }) } + ] : + [{ target: "labels", mutation: () => ({ active: false }) }]; + }, + onTouchEnd: () => { + return props.activateData ? + [ + { target: "labels", mutation: () => ({ active: false }) }, + { target: "data", mutation: () => ({ active: false }) } + ] : + [{ target: "labels", mutation: () => ({ active: false }) }]; + } } - } - }]; + }]; + }; shouldComponentUpdate(nextProps) { return !Collection.areVictoryPropsEqual(this.props, nextProps); diff --git a/src/victory-util/events.js b/src/victory-util/events.js index b8af508..70eb91f 100644 --- a/src/victory-util/events.js +++ b/src/victory-util/events.js @@ -214,7 +214,9 @@ export default { getComponentEvents(props, components) { const events = Array.isArray(components) && components.reduce((memo, componentName) => { const component = props[componentName]; - const componentEvents = component && component.type && component.type.defaultEvents; + const defaultEvents = component && component.type && component.type.defaultEvents; + const componentEvents = isFunction(defaultEvents) ? + defaultEvents(component.props) : defaultEvents; memo = Array.isArray(componentEvents) ? memo.concat(...componentEvents) : memo; return memo; }, []);