所以我有一个脉轮UI图标按钮

<IconButton
   aria-label="Left Arrow"

我想删除咏叹调标签--我为什么要这样做?因为IconButton位于树的aria-hidden部分内,因此标签是多余的.

但如果我删除它,我会收到以下类型脚本投诉

 ../../node_modules/@chakra-ui/button/dist/icon-button.d.ts:23:5
web:tsc:     23     "aria-label": string;
web:tsc:            ~~~~~~~~~~~~
web:tsc:     '"aria-label"' is declared here.

我怎样才能制作脉轮图标按钮,而不会给它添加不必要的咏叹调标签.

推荐答案

我们来看看source code<IconButton />

"use client"

import { forwardRef } from "react"
import { Button, ButtonProps } from "./button"

export interface IconButtonProps extends ButtonProps {
  /**
   * A11y: A label that describes the button
   */
  "aria-label": string
}

/**
 * Icon button renders an icon within a button.
 *
 * @see Docs https://chakra-ui.com/docs/components/icon-button
 */
export const IconButton = forwardRef<HTMLButtonElement, IconButtonProps>(
  function IconButton(props, ref) {
    return <Button padding="0" ref={ref} {...props} />
  },
)

IconButton.displayName = "IconButton"

本质上,IconButton只是一个Button,带有一个强制性的额外props aria-label和强制性的padding=0.正如您所看到的,它没有自己的变体、风格或任何东西.因此,如果您不喜欢aria-label,您可以简单地使用Button并带有填充=0.

Typescript相关问答推荐

为什么在TypScript中将类型守护的返回类型写成This is(

如何根据参数的值缩小函数内的返回类型?

有没有办法适当缩小类型?

Angular 17 -如何使用新的@if语法在对象中使用Deliverc值

TypeScript类型不匹配:在返回类型中处理已经声明的Promise Wrapper

接口的额外属性作为同一接口的方法的参数类型'

如何使函数接受类型脚本中具有正确类型的链接修饰符数组

有没有办法解决相互影响的路由之间的合并?

类型脚本基于数组作为泛型参数展开类型

参数属性类型定义的REACT-RUTER-DOM中的加载器属性错误

我可以使用TypeScrip从字符串词典/记录中填充强类型的环境对象吗?

尽管对象的类型已声明,但未解析的变量<;变量

如何将TS泛型用于react-hook-form接口?

在React中定义props 的不同方式.FunctionalComponent

为什么我的导航在使用Typescript的React Native中不起作用?

为什么在泛型方法中解析此promise 时会出现类型错误?

打印脚本中正则函数和函数表达式的不同类型缩小行为

如何键入并类型的函数&S各属性

元组解释

Mongodb TypeError:类继承 events_1.EventEmitter 不是对象或 null