Skip to content

Commit

Permalink
Merge pull request #453 from lumapps/fix/tooltip-on-disabled
Browse files Browse the repository at this point in the history
fix(tooltip): make tooltip work on disabled anchor
  • Loading branch information
pidupuis authored Aug 4, 2020
2 parents 0404e4a + 95e3e73 commit 9c96f4d
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 3 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed
### Fixed

- Fixed and improved `Dropdown` shrinking system.
- Fixed unwanted scroll to the top on the screen when opening a `Dropdown`.
- Fix `Tooltip` display on disabled anchor.

### Changed

- Improved `useInfiniteScroll` to prevent conditionnal hooks.
- Improved `useInfiniteScroll` to prevent conditional hooks.

### Added

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,8 @@
font-size: $lumx-tooltip-font-size;
line-height: $lumx-tooltip-line-height;
}

&-anchor-wrapper {
display: inline-block;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,11 @@ export const TooltipWithDropdown = () => {
</>
);
};

export const TooltipOnDisabledButton = () => {
return (
<Tooltip label={'Tooltip on disabled button'}>
<Button disabled>Empty</Button>
</Tooltip>
);
};
9 changes: 9 additions & 0 deletions packages/lumx-react/src/components/tooltip/Tooltip.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ describe(`<${Tooltip.displayName}>`, () => {
);
expect(wrapper).toMatchSnapshot();
});

it('should work on disabled elements', () => {
const wrapper = shallow(
<Tooltip label="Tooltip on disabled button" forceOpen>
<Button disabled>Empty</Button>
</Tooltip>,
);
expect(wrapper).toMatchSnapshot();
});
});

// Common tests suite.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,47 @@ exports[`<Tooltip> Snapshots and structure should return children when empty lab
</Fragment>
`;
exports[`<Tooltip> Snapshots and structure should work on disabled elements 1`] = `
<Fragment>
<div
aria-describedby="tooltip-123"
className="lumx-tooltip-anchor-wrapper"
>
<Button
disabled={true}
>
Empty
</Button>
</div>
<Portal
containerInfo={<body />}
>
<div
aria-label="Tooltip on disabled button"
className="lumx-tooltip lumx-tooltip--position-bottom"
id="tooltip-123"
role="tooltip"
style={
Object {
"left": "0",
"position": "absolute",
"top": "0",
}
}
>
<div
className="lumx-tooltip__arrow"
/>
<div
className="lumx-tooltip__inner"
>
Tooltip on disabled button
</div>
</div>
</Portal>
</Fragment>
`;
exports[`<Tooltip> Snapshots and structure should wrap children 1`] = `
<Fragment>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ export const useInjectTooltipRef = (
): ReactNode => {
return useMemo(() => {
const ariaProps = { 'aria-describedby': isOpen ? id : undefined };
if (children && get(children, '$$typeof')) {
if (
children &&
get(children, '$$typeof') &&
get(children, 'props.disabled') !== true &&
get(children, 'props.isDisabled') !== true
) {
const type = get(children, 'type');

// Base React HTML element.
Expand Down

0 comments on commit 9c96f4d

Please sign in to comment.