1 | # Upgrading to 3.0 from 2.x
|
2 |
|
3 | ember-tooltips 3.x replaces the underlying tooltip implementation with the robust
|
4 | and mature [`tooltip.js`](https://popper.js.org/tooltip-examples.html) library powered by [`popper.js`](https://popper.js.org/). It has enabled a simpler ember-tooltips implementation,
|
5 | while providing more functionality and coverage for use cases not easily supported
|
6 | by earlier versions of ember-tooltips.
|
7 |
|
8 | ## Migrating existing code
|
9 |
|
10 | We've done our best to make the upgrade from 2.x to 3.x as smooth as possible,
|
11 | by preserving a similar component API and mostly compatible test helpers.
|
12 |
|
13 | ### 1. Update component names
|
14 |
|
15 | ember-tooltips now provides one component for tooltips, `ember-tooltip`, and one
|
16 | component for popovers, `ember-popover`.
|
17 |
|
18 | For the most part you can find-and-replace all uses of `tooltip-on-component`
|
19 | and `tooltip-on-element` with `ember-tooltip`, and `popover-on-component` and
|
20 | `popover-on-element` with `ember-popover`.
|
21 |
|
22 | ### 2. Remove deprecated options
|
23 |
|
24 | If you have specified these options in the past, you should remove them, as they
|
25 | no longer apply to ember-tooltips 3.x:
|
26 |
|
27 | * `setPin` - No longer needed
|
28 | * `keepInWindow` - All tooltips are now kept in the window by default. See
|
29 | [`popperOptions`](README.md#popper-options) for overriding this behavior via popper.js modifiers.
|
30 | * `enableLazyRendering`
|
31 |
|
32 | e.g.
|
33 |
|
34 | ```patch
|
35 | - {{#tooltip-on-element
|
36 | - class="user-banner__photo__tooltip js-user-photo-tooltip"
|
37 | - enableLazyRendering=true
|
38 | - side='right'}}
|
39 | + {{#ember-tooltip
|
40 | + class="js-user-photo-tooltip"
|
41 | + tooltipClassName="ember-tooltip user-banner__photo__tooltip"
|
42 | + side='right'}}
|
43 | <img src={{user.photo_url}} alt="User photo" />
|
44 | - {{/tooltip-on-element}}
|
45 | + {{/ember-tooltip}}
|
46 | ```
|
47 |
|
48 | ### 3. Update `class` and `tooltipClassName`
|
49 |
|
50 | When specifying `class` with an `ember-tooltip`, this will apply to the tooltip
|
51 | wrapper component, but will not contain the actual tooltip content. `class` may
|
52 | still be used for targeting tooltips using the `ember-tooltips` test helpers.
|
53 |
|
54 | For other uses where you're looking to set a class on the actual tooltip used
|
55 | for display (e.g. changing styling), use `tooltipClassName`, which will
|
56 | apply to the `popper.js` tooltip instance in the DOM.
|
57 |
|
58 | e.g.
|
59 |
|
60 | ```hbs
|
61 | {{!-- app/components/some-component.hbs --}}
|
62 | {{ember-tooltip
|
63 | text="Hello"
|
64 | class="js-my-test-tooltip"
|
65 | tooltipClassName="ember-tooltip tooltip-warning"
|
66 | }}
|
67 | ```
|
68 |
|
69 | ```css
|
70 | /* app/styles/my-tooltips.css */
|
71 | .tooltip-warning {
|
72 | background-color: yellow;
|
73 | color: black;
|
74 | }
|
75 | ```
|
76 |
|
77 | ```javascript
|
78 | // tests/integration/components/some-component-test.js
|
79 | assertTooltipContent(assert, {
|
80 | contentString: 'Hello',
|
81 | selector: '.js-my-test-tooltip',
|
82 | })
|
83 | ```
|
84 |
|
85 | ### 4. Migrating test helpers
|
86 |
|
87 | The test helpers have remained with the same API. However, there are a few notable
|
88 | changes:
|
89 |
|
90 | #### 4.1 Updating test helper import path
|
91 |
|
92 | The test helper import paths have changed. Update `YOUR_APP_MODULE/tests/helpers/ember-tooltips` to `ember-tooltips/test-support`
|
93 |
|
94 | ```patch
|
95 | import {
|
96 | assertTooltipVisible,
|
97 | assertTooltipNotVisible,
|
98 | - findTooltip,
|
99 | - triggerTooltipTargetEvent
|
100 | -} from 'my-cool-app/tests/helpers/ember-tooltips';
|
101 | + findTooltip
|
102 | +} from 'ember-tooltips/test-support';
|
103 | ```
|
104 |
|
105 | #### 4.2 Replace `triggerTooltipTargetEvent` test helper
|
106 |
|
107 | The `triggerTooltipTargetEvent` test helper has been removed.
|
108 | Please use `triggerEvent` from `@ember/test-helpers` (or `ember-native-dom-helpers`,
|
109 | if you're not using the latest test helpers.)
|
110 |
|
111 | ```patch
|
112 | - it('shows the thing I want when condition is true', function() {
|
113 | + it('shows the thing I want when condition is true', async function() {
|
114 | await render(hbs`{{ember-tooltip text='Hello' class="my-tooltip-target"}}`);
|
115 | const someTooltipTarget = this.$('.my-tooltip-target');
|
116 | - triggerTooltipTargetEvent(someTooltipTarget, 'mouseenter');
|
117 | + await triggerEvent(someTooltipTarget[0], 'mouseenter');
|
118 | ```
|
119 |
|
120 | #### 4.3 Specifying `targetSelector` where needed
|
121 |
|
122 | While the test helper APIs remain unchanged, due to DOM structure changes in
|
123 | ember-tooltips, you may need to specify the [`targetSelector`](README.md#test-helper-option-targetselector)
|
124 | option to target the correct tooltip.
|
125 |
|
126 | Luckily, your test suite should let you know where this is needed!
|
127 |
|
128 | ### 5. Updating any CSS Overrides
|
129 |
|
130 | If you were previously overriding CSS styles of `ember-tooltips`, your rules will
|
131 | need to be updated to support 3.x. While by default, the tooltips should look about
|
132 | the same, the underlying DOM structure and CSS classes used have changed.
|
133 |
|
134 | If you were using CSS workarounds for positioning the tooltip, they may no longer
|
135 | be needed, as `popper.js` is smarter about positioning and provides
|
136 | some broader control over it. For example, position variants supported by
|
137 | `popper.js` may supplant the need for some custom positioning CSS. See [`side`](README.md#test-helper-option-side)
|
138 | option for more details.
|