Skip to content
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 #3692: Button tooltip remaining displayed after disable #3696

Merged
merged 1 commit into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions components/doc/megamenu/templatingdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export function TemplatingDoc(props) {
]
}
];
const start = <img alt="logo" src="showcase/images/logo.png" onError={(e) => (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} height="40" className="mr-2"></img>;
const start = <img alt="logo" src="images/logo.png" onError={(e) => (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} height="40" className="mr-2"></img>;
const end = <InputText placeholder="Search" type="text" style={{ width: '12rem' }} />;

const code = {
Expand Down Expand Up @@ -244,7 +244,7 @@ export default function TemplatingDoc() {
]
}
];
const start = <img alt="logo" src="showcase/images/logo.png" onError={(e) => e.target.src='https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png'} height="40" className="mr-2"></img>;
const start = <img alt="logo" src="images/logo.png" onError={(e) => e.target.src='https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png'} height="40" className="mr-2"></img>;
const end = <InputText placeholder="Search" type="text" style={{width: '12rem'}} />;

return (
Expand Down Expand Up @@ -369,7 +369,7 @@ export default function TemplatingDoc() {
]
}
];
const start = <img alt="logo" src="showcase/images/logo.png" onError={(e) => e.target.src='https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png'} height="40" className="mr-2"></img>;
const start = <img alt="logo" src="images/logo.png" onError={(e) => e.target.src='https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png'} height="40" className="mr-2"></img>;
const end = <InputText placeholder="Search" type="text" style={{width: '12rem'}} />;

return (
Expand Down
6 changes: 3 additions & 3 deletions components/doc/menubar/customdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export function CustomDoc(props) {
}
];

const start = <img alt="logo" src="showcase/images/logo.png" onError={(e) => (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} height="40" className="mr-2"></img>;
const start = <img alt="logo" src="images/logo.png" onError={(e) => (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} height="40" className="mr-2"></img>;
const end = <InputText placeholder="Search" type="text" />;

const code = {
Expand Down Expand Up @@ -268,7 +268,7 @@ const items = [
}
];

const start = <img alt="logo" src="showcase/images/logo.png" onError={(e) => e.target.src='https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png'} height="40" className="mr-2"></img>;
const start = <img alt="logo" src="images/logo.png" onError={(e) => e.target.src='https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png'} height="40" className="mr-2"></img>;
const end = <InputText placeholder="Search" type="text" />;

return (
Expand Down Expand Up @@ -409,7 +409,7 @@ const items = [
}
];

const start = <img alt="logo" src="showcase/images/logo.png" onError={(e) => e.target.src='https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png'} height="40" className="mr-2"></img>;
const start = <img alt="logo" src="images/logo.png" onError={(e) => e.target.src='https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png'} height="40" className="mr-2"></img>;
const end = <InputText placeholder="Search" type="text" />;

return (
Expand Down
4 changes: 2 additions & 2 deletions components/doc/messages/staticdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function StaticDoc() {
msgs1.current.show({
severity: 'info', sticky: true, content: (
<React.Fragment>
<img alt="logo" src="showcase/images/logo.png" onError={(e) => e.target.src='https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png'} width="32" />
<img alt="logo" src="images/logo.png" onError={(e) => e.target.src='https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png'} width="32" />
<div className="ml-2">Always bet on Prime.</div>
</React.Fragment>
)
Expand All @@ -59,7 +59,7 @@ export default function StaticDoc() {
msgs1.current?.show({
severity: 'info', sticky: true, content: (
<React.Fragment>
<img alt="logo" src="showcase/images/logo.png" onError={(e) => e.target.src='https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png'} width="32" />
<img alt="logo" src="images/logo.png" onError={(e) => e.target.src='https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png'} width="32" />
<div className="ml-2">Always bet on Prime.</div>
</React.Fragment>
)
Expand Down
10 changes: 5 additions & 5 deletions components/doc/tooltip/mousetrackdoc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Tooltip } from '../../lib/tooltip/Tooltip';
import { Button } from '../../lib/button/Button';
import { Tooltip } from '../../lib/tooltip/Tooltip';
import { DocSectionCode } from '../common/docsectioncode';
import { DocSectionText } from '../common/docsectiontext';

Expand All @@ -9,7 +9,7 @@ export function MouseTrackDoc(props) {
<Button type="button" label="Save" icon="pi pi-check" tooltip="Save" tooltipOptions={{ position: 'bottom', mouseTrack: true, mouseTrackTop: 15 }} /

<Tooltip target=".logo" mouseTrack mouseTrackLeft={10} />
<img className="logo ml-2" alt="logo" src="showcase/images/logo.png" onError={(e) => (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} data-pr-tooltip="PrimeReact-Logo" height="80px" />
<img className="logo ml-2" alt="logo" src="images/logo.png" onError={(e) => (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} data-pr-tooltip="PrimeReact-Logo" height="80px" />
`,
javascript: `
import { Tooltip } from 'primereact/tooltip';
Expand All @@ -22,7 +22,7 @@ export default function MouseTrackDoc() {
<Button type="button" label="Save" icon="pi pi-check" tooltip="Save" tooltipOptions={{ position: 'bottom', mouseTrack: true, mouseTrackTop: 15 }} />

<Tooltip target=".logo" mouseTrack mouseTrackLeft={10} />
<img className="logo ml-2" alt="logo" src="showcase/images/logo.png" onError={(e) => (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} data-pr-tooltip="PrimeReact-Logo" height="80px" />
<img className="logo ml-2" alt="logo" src="images/logo.png" onError={(e) => (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} data-pr-tooltip="PrimeReact-Logo" height="80px" />
</div>
);
}
Expand All @@ -38,7 +38,7 @@ export default function MouseTrackDoc() {
<Button type="button" label="Save" icon="pi pi-check" tooltip="Save" tooltipOptions={{ position: 'bottom', mouseTrack: true, mouseTrackTop: 15 }} />

<Tooltip target=".logo" mouseTrack mouseTrackLeft={10} />
<img className="logo ml-2" alt="logo" src="showcase/images/logo.png" onError={(e) => (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} data-pr-tooltip="PrimeReact-Logo" height="80px" />
<img className="logo ml-2" alt="logo" src="images/logo.png" onError={(e) => (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} data-pr-tooltip="PrimeReact-Logo" height="80px" />
</div>
);
}
Expand All @@ -54,7 +54,7 @@ export default function MouseTrackDoc() {
<Button type="button" label="Save" icon="pi pi-check" tooltip="Save" tooltipOptions={{ position: 'bottom', mouseTrack: true, mouseTrackTop: 15 }} />

<Tooltip target=".logo" mouseTrack mouseTrackLeft={10} />
<img className="logo ml-2" alt="logo" src="showcase/images/logo.png" onError={(e) => (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} data-pr-tooltip="PrimeReact-Logo" height="80px" />
<img className="logo ml-2" alt="logo" src="images/logo.png" onError={(e) => (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} data-pr-tooltip="PrimeReact-Logo" height="80px" />
</div>
<DocSectionCode code={code} />
</>
Expand Down
12 changes: 6 additions & 6 deletions components/doc/tooltip/templatedoc.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Tooltip } from '../../lib/tooltip/Tooltip';
import { Button } from '../../lib/button/Button';
import { Tooltip } from '../../lib/tooltip/Tooltip';
import { DocSectionCode } from '../common/docsectioncode';
import { DocSectionText } from '../common/docsectiontext';

export function TemplateDoc(props) {
const code = {
basic: `
<Tooltip target=".custom-tooltip-btn">
<img alt="logo" src="showcase/images/logo.png" onError={(e) => (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} data-pr-tooltip="PrimeReact-Logo" height="80px" />
<img alt="logo" src="images/logo.png" onError={(e) => (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} data-pr-tooltip="PrimeReact-Logo" height="80px" />
</Tooltip>

<Button className="custom-tooltip-btn" type="button" label="Save" icon="pi pi-check" />
Expand All @@ -21,7 +21,7 @@ export default function TemplateDoc() {
return (
<div>
<Tooltip target=".custom-tooltip-btn">
<img alt="logo" src="showcase/images/logo.png" onError={(e) => (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} data-pr-tooltip="PrimeReact-Logo" height="80px" />
<img alt="logo" src="images/logo.png" onError={(e) => (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} data-pr-tooltip="PrimeReact-Logo" height="80px" />
</Tooltip>

<Button className="custom-tooltip-btn" type="button" label="Save" icon="pi pi-check" />
Expand All @@ -34,11 +34,11 @@ import { Tooltip } from 'primereact/tooltip';
import { Button } from 'primereact/button';

export default function TemplateDoc() {

return (
<div>
<Tooltip target=".custom-tooltip-btn">
<img alt="logo" src="showcase/images/logo.png" onError={(e) => (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} data-pr-tooltip="PrimeReact-Logo" height="80px" />
<img alt="logo" src="images/logo.png" onError={(e) => (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} data-pr-tooltip="PrimeReact-Logo" height="80px" />
</Tooltip>

<Button className="custom-tooltip-btn" type="button" label="Save" icon="pi pi-check" />
Expand All @@ -55,7 +55,7 @@ export default function TemplateDoc() {
</DocSectionText>
<div className="card flex align-items-center justify-content-center">
<Tooltip target=".custom-tooltip-btn">
<img alt="logo" src="showcase/images/logo.png" onError={(e) => (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} data-pr-tooltip="PrimeReact-Logo" height="80px" />
<img alt="logo" src="images/logo.png" onError={(e) => (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} data-pr-tooltip="PrimeReact-Logo" height="80px" />
</Tooltip>

<Button className="custom-tooltip-btn" type="button" label="Save" icon="pi pi-check" />
Expand Down
3 changes: 2 additions & 1 deletion components/lib/button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ export const Button = React.memo(
return null;
};

const hasTooltip = ObjectUtils.isNotEmpty(props.tooltip);
const disabled = props.disabled || props.loading;
const showTooltip = !disabled || (props.tooltipOptions && props.tooltipOptions.showOnDisabled);
const hasTooltip = ObjectUtils.isNotEmpty(props.tooltip) && showTooltip;
const otherProps = ObjectUtils.findDiffKeys(props, Button.defaultProps);
const className = classNames('p-button p-component', props.className, {
'p-button-icon-only': (props.icon || (props.loading && props.loadingIcon)) && !props.label && !props.children,
Expand Down
9 changes: 3 additions & 6 deletions components/lib/tooltip/Tooltip.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import PrimeReact from '../api/Api';
import { useMountEffect, useOverlayScrollListener, useResizeListener, useUnmountEffect, useUpdateEffect } from '../hooks/Hooks';
import { useOverlayScrollListener, useResizeListener, useUnmountEffect, useUpdateEffect } from '../hooks/Hooks';
import { Portal } from '../portal/Portal';
import { classNames, DomHandler, ObjectUtils, ZIndexUtils } from '../utils/Utils';

Expand Down Expand Up @@ -388,20 +388,17 @@ export const Tooltip = React.memo(
}
};

useMountEffect(() => {
React.useEffect(() => {
loadTargetEvents();

if (visibleState && currentTargetRef.current && isDisabled(currentTargetRef.current)) {
hide();
}
});

useUpdateEffect(() => {
loadTargetEvents();

return () => {
unloadTargetEvents();
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [show, hide, props.target]);

useUpdateEffect(() => {
Expand Down