-
-
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 10 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 |
|---|---|---|
|
|
@@ -16,13 +16,13 @@ export interface TooltipProps | |
| | 'onPopupAlign' | ||
| | 'builtinPlacements' | ||
| | 'fresh' | ||
| | 'children' | ||
| | 'mouseLeaveDelay' | ||
| | 'mouseEnterDelay' | ||
| | 'prefixCls' | ||
| | 'forceRender' | ||
| | 'popupVisible' | ||
| > { | ||
| children: React.ReactElement; | ||
| // Style | ||
| classNames?: Partial<Record<SemanticName, string>>; | ||
| styles?: Partial<Record<SemanticName, React.CSSProperties>>; | ||
|
|
@@ -79,6 +79,7 @@ const Tooltip = React.forwardRef<TooltipRef, TooltipProps>((props, ref) => { | |
| showArrow = true, | ||
| classNames, | ||
| styles, | ||
| forceRender, | ||
| ...restProps | ||
| } = props; | ||
|
|
||
|
|
@@ -113,14 +114,12 @@ const Tooltip = React.forwardRef<TooltipRef, TooltipProps>((props, ref) => { | |
| }, [showArrow, classNames?.arrow, styles?.arrow, arrowContent]); | ||
|
|
||
| // ======================== Children ======================== | ||
| const getChildren = () => { | ||
| const getChildren = (open: boolean) => { | ||
| const child = React.Children.only(children); | ||
| const originalProps = child?.props || {}; | ||
| const childProps = { | ||
| ...originalProps, | ||
| 'aria-describedby': overlay ? mergedId : null, | ||
| const ariaProps: React.AriaAttributes = { | ||
| 'aria-describedby': overlay && open ? mergedId : undefined, | ||
| }; | ||
| return React.cloneElement<any>(children, childProps) as any; | ||
| return React.cloneElement(child, ariaProps); | ||
| }; | ||
|
|
||
| // ========================= Render ========================= | ||
|
|
@@ -149,6 +148,7 @@ const Tooltip = React.forwardRef<TooltipRef, TooltipProps>((props, ref) => { | |
| afterOpenChange={afterVisibleChange} | ||
| popupMotion={motion} | ||
| defaultPopupVisible={defaultVisible} | ||
| forceRender={forceRender} | ||
| autoDestroy={destroyOnHidden} | ||
| mouseLeaveDelay={mouseLeaveDelay} | ||
| popupStyle={styles?.root} | ||
|
|
@@ -158,7 +158,7 @@ const Tooltip = React.forwardRef<TooltipRef, TooltipProps>((props, ref) => { | |
| uniqueContainerStyle={styles?.uniqueContainer} | ||
| {...extraProps} | ||
| > | ||
| {getChildren()} | ||
| {({ open }) => getChildren(open)} | ||
|
||
| </Trigger> | ||
| ); | ||
| }); | ||
|
|
||
| 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.
这个你已经不消费了,还原给解构填入吧