-
-
Notifications
You must be signed in to change notification settings - Fork 199
feat: better a11y #509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: better a11y #509
Changes from 7 commits
dece1b0
b7388d4
2a4f330
625204d
e081d1b
3c7e909
095b9cb
e505c88
fe2e017
403dd52
e1082bf
ac227c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ import type { ActionType, AlignType } from '@rc-component/trigger/lib/interface' | |
| import useId from '@rc-component/util/lib/hooks/useId'; | ||
| import { clsx } from 'clsx'; | ||
| import * as React from 'react'; | ||
| import { useImperativeHandle, useRef } from 'react'; | ||
| import { useImperativeHandle, useRef, useState } from 'react'; | ||
| import { placements } from './placements'; | ||
| import Popup from './Popup'; | ||
|
|
||
|
|
@@ -79,6 +79,7 @@ const Tooltip = React.forwardRef<TooltipRef, TooltipProps>((props, ref) => { | |
| showArrow = true, | ||
| classNames, | ||
| styles, | ||
| forceRender, | ||
| ...restProps | ||
| } = props; | ||
|
|
||
|
|
@@ -89,10 +90,22 @@ const Tooltip = React.forwardRef<TooltipRef, TooltipProps>((props, ref) => { | |
|
|
||
| const extraProps: Partial<TooltipProps & TriggerProps> = { ...restProps }; | ||
|
|
||
| if ('visible' in props) { | ||
| const isControlled = 'visible' in props; | ||
|
|
||
| if (isControlled) { | ||
| extraProps.popupVisible = props.visible; | ||
| } | ||
|
|
||
| const [innerVisible, setInnerVisible] = useState(() => defaultVisible || false); | ||
| const mergedVisible = isControlled ? props.visible : innerVisible; | ||
|
|
||
| const handleVisibleChange = (nextVisible: boolean) => { | ||
|
||
| if (!isControlled) { | ||
| setInnerVisible(nextVisible); | ||
| } | ||
| onVisibleChange?.(nextVisible); | ||
| }; | ||
|
|
||
| // ========================= Arrow ========================== | ||
| // Process arrow configuration | ||
| const mergedArrow = React.useMemo(() => { | ||
|
|
@@ -118,7 +131,7 @@ const Tooltip = React.forwardRef<TooltipRef, TooltipProps>((props, ref) => { | |
| const originalProps = child?.props || {}; | ||
| const childProps = { | ||
| ...originalProps, | ||
| 'aria-describedby': overlay ? mergedId : null, | ||
| 'aria-describedby': overlay && mergedVisible ? mergedId : null, | ||
| }; | ||
| return React.cloneElement<any>(children, childProps) as any; | ||
| }; | ||
|
|
@@ -145,10 +158,11 @@ const Tooltip = React.forwardRef<TooltipRef, TooltipProps>((props, ref) => { | |
| ref={triggerRef} | ||
| popupAlign={align} | ||
| getPopupContainer={getTooltipContainer} | ||
| onOpenChange={onVisibleChange} | ||
| onOpenChange={handleVisibleChange} | ||
| afterOpenChange={afterVisibleChange} | ||
| popupMotion={motion} | ||
| defaultPopupVisible={defaultVisible} | ||
| forceRender={forceRender} | ||
|
||
| autoDestroy={destroyOnHidden} | ||
| mouseLeaveDelay={mouseLeaveDelay} | ||
| popupStyle={styles?.root} | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |||||
| "declaration": true, | ||||||
| "skipLibCheck": true, | ||||||
| "esModuleInterop": true, | ||||||
| "types": ["@testing-library/jest-dom"], | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By adding the
Suggested change
Rules ReferencesFootnotes
|
||||||
| "paths": { | ||||||
| "@/*": [ | ||||||
| "src/*" | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
还是有点浪费,多了一个 state update 就多了一个 re-render。我去给 trigger 的 renderProps 加一个 info 好了