-
Notifications
You must be signed in to change notification settings - Fork 0
Add tooltip to checkboxes #125
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
c27b761
52d497d
6c21933
3bef30f
eb14526
107e5b3
b2bfd8e
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 |
|---|---|---|
| @@ -1,8 +1,10 @@ | ||
| import { useRef } from 'react'; | ||
|
Contributor
Author
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. npx tsc --noEmit passes clean. False positive. |
||
| import styled from 'styled-components'; | ||
| import { colors } from '../theme'; | ||
| import { Button, OverlayArrow, Tooltip as AriaTooltip, TooltipTrigger } from 'react-aria-components'; | ||
| import { Info } from './svgs/Info'; | ||
| import {mergeProps, Placement, useTooltip} from 'react-aria'; | ||
| import { useTooltipTriggerState } from 'react-stately'; | ||
| import {mergeProps, Placement, useTooltip, useTooltipTrigger} from 'react-aria'; | ||
|
|
||
| const tooltipStyles = ` | ||
| box-shadow: 0 0.8rem 2rem rgba(0 0 0 / 0.1); | ||
|
|
@@ -113,4 +115,20 @@ export const CustomTooltip = ({ state, ...props }: any) => { | |
| </OverlayArrow> | ||
| </StyledCustomTooltip> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| // Shared logic for showing a CustomTooltip on a label-wrapped input (Checkbox, Radio). | ||
| export const useLabelTooltip = (tooltipText?: string, placement: Placement = 'right') => { | ||
| const state = useTooltipTriggerState({ delay: 0 }); | ||
| const triggerRef = useRef(null); | ||
| const { triggerProps, tooltipProps } = useTooltipTrigger({ delay: 0 }, state, triggerRef); | ||
|
|
||
| return { | ||
| triggerRef, | ||
| triggerProps, | ||
| openTooltip: () => state.open(), | ||
| tooltip: tooltipText && state.isOpen | ||
| ? <CustomTooltip state={state} {...tooltipProps} placement={placement}>{tooltipText}</CustomTooltip> | ||
| : null, | ||
| }; | ||
|
Comment on lines
+124
to
+135
Contributor
Author
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. stripping |
||
| }; | ||
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.
tooltip behavior has not changed. Visually inspected and used VoiceOver to check accessibility.