score:2
You are editing the className
attribute of the .arrow
dom node directly via $target.toggleClass('up down');
, but not the props of the ReactComponent that spawned it.
In your code, arrow
is a ReactComponent, not a DOM Node. To find the DOM Node of a ReactComponent, use React.findDOMNode(component)
.
The React way would be to ditch jQuery for such a trivial task and instead update your component state with a flag that indicates if the accordion is active.
getInitialState: function() {
return {
accordionActive: false
};
},
toggleFooter: function(e) {
this.setState({
accordionActive: !this.state.accordionActive
});
},
render: function() {
return (
<div>
<ul className={'project-accordion' + (this.state.accordionActive ? ' active' : '')}>
{this.props.steps.map(function(step, i){
return <AccordionStep step={step} key={i}/>
})}
</ul>
<span className="footer-info">{this.props.completedSteps} of {this.props.totalSteps} steps completed</span>
<span className={'arrow mt1 ' + (this.state.accordionActive ? 'up' : 'down')} onClick={this.toggleFooter}></span>
</div>
);
}
Using the classNames
module, you can replace those ugly className
computation with
className={classNames('project-accordion', this.state.accordionActive && 'active')}
and
className={classNames('arrow mt1', this.state.accordionActive ? 'up' : 'down')}
The value of arrow.props.className
should then always be either arrow mt1 up
or arrow mt1 down
.
Source: stackoverflow.com
Related Query
- Testing React click event in Jest fails because the Jquery can't be applied - How can I test it?
- How to test a className with the Jest and React testing library
- How to get React to listen for a click event called in Jquery
- How to prevent a simple React modal from being closed if you either start or end the click event inside the modal?
- How to test the child component render text after the button on the parent component click with react testing library?
- How do I get the id of div wrapper in React when childnodes are the click event target?
- How to test button that on click renders html element within the same component in React testing library, Jest?
- How to ignore a jest mock after the first test when testing react reducer
- How to mock history.push with the new React Router Hooks using Jest
- How Snapshot testing works and what does toMatchSnapshot( ) function do in Jest Snapshot testing for React components?
- How to mock out sub-components when unit testing a React component with Jest
- How to unit test a react event handler that contains history.push using Jest and Enzyme?
- How to simulate mouse over event on a div using enzyme for testing a react application?
- Testing click event in React Testing Library
- Test that a click event in React updates the HTML
- How can I find and click a button that has no text using React Testing Library?
- How to get the react component instance corresponding to event.target element in a click handler?
- How I can disable a button in React js for 5 seconds after click event
- Jest and React Testing Library, how to test if an element is hidden?
- How to test the state of a functional component in React with Jest (No Enzyme)
- How to add click event with React createElement
- How to get the element with the testid using react testing library?
- How can you remove a Jquery Document Click Listeners Effecting React Element?
- how can I test if useState hook has been called with jest and react testing library?
- How to toggle class for the only one element on click in react
- React - how to trigger preventDefault() before the synthetic event is recycled?
- Expect jest mock to have been called with an argument fails in react testing library
- how to write inline js event handler code in the react component using "this"
- How to load a React Component in an existing jQuery application on jQuery click
- Testing images imported in the component with Jest + React Native
More Query from same tag
- Reducer fires and it inadvertently clears input
- How do I get my React TextField to open the number pad when inputting on a mobile device?
- Accessing Axios error codes in interceptor
- When using ES6, how can an imported function be undefined in one file, and not in another?
- Reactjs, How can I add select option attributes values to state
- React-big-calendar - don't know how to store dates in mongoDB
- Call hook from another hook in react
- Javascript dictionary and to add values
- React - Dynamically Import Components
- Multiple setState using useState but trigger only once?
- How to fetch API in Node.js and send to Reactjs ( youtube video included for more detail explain)
- Reactjs nested routes is not redirect to child screen
- Infinite render caused by child component taking props from parent
- React: Props undefined when passed from Parent to Child Function Component
- spec.type must be defined in react-dnd
- Event handling on reactjs
- Why React says "Logout is not a function ?"
- React hooks - useEffect method keeps fetching
- What is the best pattern for dynamically rendering components?
- React Hooks - Set State variable from Promise in another function
- Fetch and sessions and CORS
- Issue with Typesense with error "network error"
- upload zip file from reactjs to nodejs
- why axios return promise error in reactjs
- How to setup global variables in apollo-client
- How to make a specific peace of code visible when there is a match on a Route? react-router
- react app not picking up .env.development files?
- REACT: conditionally rendering a alert if field left blank
- Remove the logo text if its size is 660 pixels
- Several ternary operators nested within