Skip to content

Commit

Permalink
Add deprecation warning when $.tooltip is used outside of the Toolt…
Browse files Browse the repository at this point in the history
…ip component
  • Loading branch information
davwheat committed May 9, 2021
1 parent 651e551 commit 356df4d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
18 changes: 11 additions & 7 deletions js/src/common/components/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,16 @@ export default class Tooltip extends Component<TooltipAttrs> {
} = this.attrs;

// https://getbootstrap.com/docs/3.3/javascript/#tooltips-options
this.$().tooltip({
html,
delay,
placement: position,
// Fancy "hack" to assemble the trigger string
trigger: classList('hover', [showOnFocus && 'focus']) as TooltipCreationOptions['trigger'],
});
this.$().tooltip(
{
html,
delay,
placement: position,
// Fancy "hack" to assemble the trigger string
trigger: classList('hover', [showOnFocus && 'focus']) as TooltipCreationOptions['trigger'],
},
// @ts-expect-error We don't want this arg to be part of the public API. It only exists to prevent deprecation warnings when using `$.tooltip` in this component.
'DANGEROUS_tooltip_jquery_fn_deprecation_exempt'
);
}
}
15 changes: 15 additions & 0 deletions js/src/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,18 @@ import * as Extend from './extend/index';
export { Extend };

import './utils/arrayFlatPolyfill';

const tooltipGen = $.fn.tooltip;

// Remove in a future version of Flarum.
$.fn.tooltip = function (options, caller) {
// Show a warning when `$.tooltip` is used outside of the Tooltip component.
// This functionality is deprecated and should not be used.
if (['DANGEROUS_tooltip_jquery_fn_deprecation_exempt'].includes(caller)) {
console.warn(
"Calling `$.tooltip` is now deprecated. Please use the `<Tooltip>` component exposed by flarum/core instead. `$.tooltip` may be removed in a future version of Flarum.\n\nIf this component doesn't meet your requirements, please open an issue: https://github.com/flarum/core/issues/new?assignees=davwheat&labels=type/bug,needs-verification&template=bug-report.md&title=Tooltip%20component%20unsuitable%20for%20use%20case"
);
}

tooltipGen.bind(this)(options);
};

0 comments on commit 356df4d

Please sign in to comment.