Question: failed to read attribute 'tabIndex' when setAttribute in useEffect
See original GitHub issueconst inputRef = useRef(null);
useEffect(() => {
if (tabIndex){ // if tabIndex provided
inputRef.current.setAttribute('tabindex', tabIndex);
}
}, []);
return <div><input ref={inputRef} disabled={false} /></div>
test
const wrapper = mount(<Component tabIndex={10}/>);
console.log(wrapper.update().find('input').props())
expect(wrapper.update().find('input').props()['tabindex']).toEqual(10); // undefined
// => {
// disabled: false
// }
// no tabIndex nor tabindex
Both of
wrapper.update().find('input').props()['tabindex']
and
wrapper.update().find('input').props()['tabIndex']
are undefined
Anything wrong here?
API
- shallow
- mount
- render
Version
library | version |
---|---|
enzyme | 3.10.0 |
react | 16.8.6 |
react-dom | 16.8.6 |
react-test-renderer | |
adapter (below) | 1.14.0 |
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Tabindex not working in Chrome (React app) - Stack Overflow
I assigned tabindex=0 to the required elements to be tabbable in order of appearance. My problem is: It does not work in Chrome...
Read more >tabindex - HTML: HyperText Markup Language | MDN
The tabindex global attribute indicates that its element can be focused, and where it participates in sequential keyboard navigation ...
Read more >How to conditionally add attributes to React components?
Evidently, with some attributes, React is smart enough to omit the attribute if the value you pass to it is not truthy. For...
Read more >Building an accessible menubar component using React
setAttribute ("tabindex", "0"); currentNode?.focus(); } }, [currentIndex, ...
Read more >Need to set tabIndex=0 to enable tab navigation
I recently answered a Stack Overflow question, React focus items list in child component after action from a different child component and ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@ljharb https://github.com/edwardfhsiao/enzyme-hooks-test-repo Please check this out,
npm i
thennpm run test
or see the site runnpm run server
@kanaabe I end up doing
<Textarea {...attributes}>
instead of<Textarea tabIndex={tabIndex} maxLength={maxLength} id={id} ...>
.Basically just not test it explicitly