-
Notifications
You must be signed in to change notification settings - Fork 105
fix(ui-a11y-utils): prevent clicking on a Tooltip from closing the pa… #1905
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
fix(ui-a11y-utils): prevent clicking on a Tooltip from closing the pa… #1905
Conversation
|
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.
This wont work if I put HTML content into the tooltip, e.g.
const TestModal = () => {
const [open, setOpen] = useState(false)
return (
<div style={{ padding: "0 0 16rem 0" }}>
<Button onClick={() => {setOpen(true)}} >Show the Modal</Button>
<Modal
label="modal"
open={open}
onDismiss={() => {setOpen(false)}}
shouldCloseOnDocumentClick
>
<Modal.Header>
<CloseButton placement="end" offset="small"
screenReaderLabel="Close"
onClick={() => {setOpen(false)}}
/>
<Heading>Hello World</Heading>
</Modal.Header>
<View as="div" padding="medium" id="tray-content">
<Tooltip
renderTip={<div>This wont work :(</div>}
mountNode={document.getElementById("tray-content")}
>
<Text>This text has a tooltip</Text>
</Tooltip>
<Tooltip
renderTip={<div>This wont work :(</div>}
mountNode={document.getElementById("tray-content")}
>
<Button>This button has a tooltip</Button>
</Tooltip>
</View>
</Modal>
</div>
)
}
render(<TestModal />)
In FocusRegion
why are you using ARIA tooltip role instead isTooltip
prop of FocusRegion to determine whether its a tooltip? Now we have 2 methods of determining whether something is a tooltip (the other one is in Popover
), this feels off. If it must be determined this way you could walk up in the DOM to check for this role but this would be ugly...
…rent dialog INSTUI-4475
c18cbe8
to
4eb6c7b
Compare
!( | ||
canUseDOM && | ||
this._documentClickTarget instanceof HTMLElement && | ||
this._documentClickTarget.closest('[role="tooltip"]') |
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.
closest returns the first (starting at element) inclusive ancestor that matches selectors, and null otherwise.
@matyasf This event listener is attached to the containing dialog's I updated the code so that it now works with an HTML element as renderTip as well. It also correctly handles cases where the button is focused when the Tooltip is clicked. I’ve updated the test plan accordingly. @balzss and I tried different approaches, but this current solution using contains seemed the best (even though it's still not the prettiest). |
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.
Nice work, I like this solution :)
…rent dialog
INSTUI-4475
ISSUE:
-when user clicks on a Tooltip inside of a dialog with shouldCloseOnDocumentClick, the dialog closes
TEST PLAN:
<div>HTML content</div>
or nested HTML element like <div><div>HTML content</div></div>
, the modal should remain open