question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: failed to read attribute 'tabIndex' when setAttribute in useEffect

See original GitHub issue
const 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:open
  • Created 4 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
edwardfxiaocommented, Jun 5, 2019

@ljharb https://github.com/edwardfhsiao/enzyme-hooks-test-repo Please check this out, npm i then npm run test or see the site run npm run server

0reactions
edwardfxiaocommented, Apr 2, 2020

@kanaabe I end up doing <Textarea {...attributes}> instead of <Textarea tabIndex={tabIndex} maxLength={maxLength} id={id} ...>.

Basically just not test it explicitly

import MyComponent from './textarea.js'
<MyComponent attributes={{tabIndex: 1, maxLength: 10, id="something" ...}}>
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found