reactjs - 如何使用 Typescript 和 React 在 svg 标签 <a> 上使用 xlinkHref

标签 reactjs typescript svg xlink

我正在尝试通过实现 this simple and elegant solution 使我的 SVG 可聚焦.

我正在使用 Typescript 和 React,这是我的代码:

return (
  <g {...propsWbsComponent} >
    <a xlinkHref={"#"}>
      <rect  {...propsWbsComponentBox} />
    </a>

    <text {...propsWbsId} >
      {props.wbsComponentId}
    </text>
  </g>
}

我收到错误消息:

error TS2339: Property 'xlinkHref' does not exist on type 'HTMLProps'

我不知道该去哪里查找,如果是 Typescript 问题、React 缺少 svg 属性(尽管 xlinkHref 现在是 React 的一部分)或其他问题。

感谢您的帮助!

最佳答案

如果您设置 tabindex,SVG 可以 native 执行此操作属性。这与 HTML attribute of the same name 的工作原理相同.

关于reactjs - 如何使用 Typescript 和 React 在 svg 标签 <a> 上使用 xlinkHref,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44626599/

相关文章:

css - 如何隐藏 Material ui 表格单元格中的溢出内容而不是换行

typescript - Aurelia CLI + typescript : Cannot find module errors

javascript - 告诉我将 src/pages/api 目录移动到 src/Next.js 的配置

javascript - Google Charts - 如何将轴标签分成两行? (多个 X 轴)

html - svg 的一部分在转换后被隐藏

javascript - 在使用 react-router 时有没有办法将参数限制为某些值?

javascript - Video.js Seek Bar - 在鼠标光标后面寻找点

reactjs - 在 ReactJS 中使用 .fetch() 上传文件

typescript - Angular 2中的分层选择

ios - 如何在我的 swift 应用程序中对绘制 svg 路径进行动画处理?