最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to add tabIndex = '0' in TypeScript div? - Stack Overflow

programmeradmin0浏览0评论

I am using Typescript with NextJS, i want to add tabIndex = '0' in one of the div. but am getting this error Type 'string' is not assignable to type 'number'... how to achive this?

‹div className= 'container' tabIndex = '0'>

I am using Typescript with NextJS, i want to add tabIndex = '0' in one of the div. but am getting this error Type 'string' is not assignable to type 'number'... how to achive this?

‹div className= 'container' tabIndex = '0'>
Share Improve this question edited Aug 4, 2022 at 4:41 coagmano 5,6711 gold badge30 silver badges41 bronze badges asked Aug 4, 2022 at 4:36 MarkMark 971 silver badge8 bronze badges 1
  • Hi @Mark, for future questions please write the code into a code block instead of linking to a screenshot. I've edited this question to do so now – coagmano Commented Aug 4, 2022 at 4:43
Add a ment  | 

2 Answers 2

Reset to default 10

Instead of tabIndex='0' , you should write it as tabIndex={0}. This way Ty[escript will understand. <div className="container tabIndex={0}>

I think typescript is wrong here, since it ends up as a string in html anyway.

But to please the piler, pass tabIndex as a JS value like this:

<div className="container tabIndex={0}>
发布评论

评论列表(0)

  1. 暂无评论