pixiv / charcoal

Design system library by pixiv
https://charcoal-web.pixiv.design/
Apache License 2.0
307 stars 34 forks source link

Feat: `aria-labelledby`相当の機能が`Switch`にほしいです #564

Open mj-hd opened 3 weeks ago

mj-hd commented 3 weeks ago

必要だと思う機能の内容を書いてください

他の構造的に離れた要素でラベルを提供しているUIを表現するためaria-labelledbyかそれと同等の機能がほしいです

この機能が必要と考えられる理由を書いてください

APGによると、switchロールはaria-labelや視覚可能なテキストコンテンツの代わりにaria-labelledby属性を指定することができるとあります。 https://www.w3.org/WAI/ARIA/apg/patterns/switch/

現在の実装だと、labelか、childrenしか受け取りません。 https://github.com/pixiv/charcoal/blob/de4162c889061d424c034459e498a4f7eae18960/packages/react/src/components/Switch/index.tsx#L18

この機能があった場合にどういう動きをするかの例を書いてください

react-ariaのuseSwitchのariaPropsにこれらの値が渡り、いろいろなユーザエージェントがこれを読み取れる状態。

また、他にもaria属性はいくつかサポートされていて、aria-description/aria-describedbyなどの追加テキスト情報を提供できるものや、aria-controlsによる操作対象のUIを指定できるものがありそうです。


Switch control should expose aria-labelledby props

According to APG, switch role may have an aria-labelledby attr instead of aria-label. https://www.w3.org/WAI/ARIA/apg/patterns/switch/

In the current implementation, the Switch component only exposes aria-label and children as text content. https://github.com/pixiv/charcoal/blob/de4162c889061d424c034459e498a4f7eae18960/packages/react/src/components/Switch/index.tsx#L18

(...and, there are more aria props, aria-description and aria-describedby, aria-details attrs to represent additional text content, aria-controls to represent content controlled by the switch.)

toshusai commented 2 weeks ago

Issueの作成およびフィードバックをいただき、誠にありがとうございます。

v4.0.0の変更により、Switchのinput要素に対して任意の属性を付与できるようになる予定です。そのため、申し訳ありませんが現在 v3 のAPIに変更を加える事は検討されていません。

v4.0.0のリリース時にご確認いただければ幸いです。また、現在beta版もリリースしておりますので、そちらでもご確認いただく事ができます。

参考までに、下記はv4.0.0のSwitchのコードになります。 https://github.com/pixiv/charcoal/blob/6ce3eaf89f87ceec7cd0b5031c3f6227096c289d/packages/react/src/components/Switch/index.tsx