Skip to content

fix(ui-tooltip): ensure Esc key closes only the Tooltip when inside a…#1850

Merged
matyasf merged 1 commit intomasterfrom
INSTUI-4393_pressing_esc_on_tooltip_in_a_modal_also_closes_the_modal_underneath
Feb 3, 2025
Merged

fix(ui-tooltip): ensure Esc key closes only the Tooltip when inside a…#1850
matyasf merged 1 commit intomasterfrom
INSTUI-4393_pressing_esc_on_tooltip_in_a_modal_also_closes_the_modal_underneath

Conversation

@ToMESSKa
Copy link
Contributor

@ToMESSKa ToMESSKa commented Jan 28, 2025

… Modal
Closes: INSTUI-4393

ISSUE: When a ToolTip is inside of a Modal and closed by Esc key, the Modal closes too.

TEST PLAN:

  • use the example below
  • Click on the 'Open the modal" button
  • hover over the Tooltip
  • press Esc when the Tooltip is still shown
  • the Tooltip should be closed but the containing Modal not
  • pressing the Esc again should close the modal too
  • other Tooltip examples should work as expected without errors and should close on Esc
const Example = () => {
  const [open, setOpen] = useState(false);

  const handleButtonClick = () => {
    setOpen((state) => !state);
  };

  const renderCloseButton = () => {
    return (
      <CloseButton
        placement="end"
        offset="small"
        onClick={handleButtonClick}
        screenReaderLabel="Close"
      />
    );
  };

  return (
    <div style={{ padding: "0 0 11rem 0", margin: "0 auto" }}>
      <Button onClick={handleButtonClick}>
        {open ? "Close" : "Open"} the Modal
      </Button>
      <Modal
        open={open}
        onDismiss={() => {
          setOpen(false);
        }}
        size="auto"
        label="Hello World"
        shouldCloseOnDocumentClick
      >
        <Modal.Header>
          {renderCloseButton()}
          <Heading>Hello World</Heading>
        </Modal.Header>
        <Modal.Body>
          <Tooltip
            renderTip="Hello. I'm a tool tip"
            placement="start"
            on={["click", "hover", "focus"]}
          >
            <IconInfoLine />
          </Tooltip>
        </Modal.Body>
      </Modal>
    </div>
  );
};

render(<Example />);

@ToMESSKa ToMESSKa self-assigned this Jan 28, 2025
@github-actions
Copy link

github-actions bot commented Jan 28, 2025

PR Preview Action v1.6.0
Preview removed because the pull request was closed.
2025-02-03 14:30 UTC

@ToMESSKa ToMESSKa requested review from balzss and matyasf January 28, 2025 15:06
Copy link
Collaborator

@matyasf matyasf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work! I've tested with a few examples including the tricky one at https://instructure.design/pr-preview/pr-1850/#focus-management and it works well :)
Please @balzss test it thoroughly, this is able to mess up things

Copy link
Contributor

@balzss balzss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

works well and the change makes sense, great job

@matyasf matyasf merged commit 0e6e1e4 into master Feb 3, 2025
11 checks passed
@matyasf matyasf deleted the INSTUI-4393_pressing_esc_on_tooltip_in_a_modal_also_closes_the_modal_underneath branch February 3, 2025 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants