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

[feature] disabled attribute #120

Closed

Conversation

knownasilya
Copy link

Allows a disabled attribute to prevent showing the tooltip by any of the available methods:

{{#tooltip-on-component disabled=true}}
  My Tooltip
{{/tooltip-on-component}}

Talked about this with @sir-dunxalot on Slack.

@knownasilya
Copy link
Author

Only thing I'm not sure about is not showing the tooltip if disabled=true isShown=true..

@knownasilya
Copy link
Author

So I added LTS targets and those all pass along with 1.13, but delay is still broken with 2.10. This feature should still be mergeable, since this test failure is unrelated.

@sir-dunxalot
Copy link
Owner

@a15n I don't want to merge this without a review from you given to the effects of this on isShown. I will also do a review.

@@ -93,7 +94,7 @@ export default Ember.Component.extend({
enableLazyRendering: false,
_hasUserInteracted: false,
_hasRendered: false,
_shouldRender: computed('isShown', 'tooltipIsVisible', 'enableLazyRendering', '_hasUserInteracted', function() {
_shouldRender: computed('isShown', 'disabled', 'tooltipIsVisible', 'enableLazyRendering', '_hasUserInteracted', function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

let's move disabled to be the first property. It is the most important.

@@ -93,7 +94,7 @@ export default Ember.Component.extend({
enableLazyRendering: false,
_hasUserInteracted: false,
_hasRendered: false,
_shouldRender: computed('isShown', 'tooltipIsVisible', 'enableLazyRendering', '_hasUserInteracted', function() {
_shouldRender: computed('isShown', 'disabled', 'tooltipIsVisible', 'enableLazyRendering', '_hasUserInteracted', function() {
// if isShown, tooltipIsVisible, !enableLazyRendering, or _hasUserInteracted then
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add disabled to this note as well

@@ -102,7 +103,7 @@ export default Ember.Component.extend({

return true;

} else if (this.get('isShown') || this.get('tooltipIsVisible')) {
} else if (!this.get('disabled') && (this.get('isShown') || this.get('tooltipIsVisible'))) {

this.set('_hasRendered', true);
return true;
Copy link
Contributor

@a15n a15n Nov 30, 2016

Choose a reason for hiding this comment

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

I can't comment below this line so see lines....

111: what if enableLazyRendering=false and disabled=true?

129: what if enableLazyRendering=false but _shouldRender=false? The didInsertElement will still apply $parent event handling and could still render the tooltip, even if it's never shown (not clean)

If these happen to be edge cases you missed can you add tests for them?

Copy link
Author

Choose a reason for hiding this comment

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

should I just handle disabled once before all of these conditionals, and return false?

Copy link
Author

Choose a reason for hiding this comment

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

And what about in 128, if i skip the parent event stuff, and then disabled gets set to false, would that be rerun anywhere else?

Copy link
Contributor

Choose a reason for hiding this comment

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

"should I just handle disabled once before all of these conditionals, and return false?"

I think if you add this it'll take care of _shouldRender

if (this.get('_hasRendered')) {
  return true; // this always needs to return true if it has ever been rendered
} else if (isDisabled) {
  return false;
....

Copy link
Contributor

Choose a reason for hiding this comment

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

"And what about in 128, if i skip the parent event stuff, and then disabled gets set to false, would that be rerun anywhere else?"

You're right. If we people change isDisabled we would need to add the event listeners to the $parent. I think maybe we should make the $parent event handling a function that can be called on didInsertElement and by observing isDisabled.

We'd need good tests to cover this. It's getting fairly complex

@a15n
Copy link
Contributor

a15n commented Nov 30, 2016

So the disabled property will prevent the tooltip from being rendered if used on the tooltip-on-element and prevent the tooltip from being shown on tether-tooltip-on-element. It will prevent it regardless of isShown and user interaction. Am I understanding this correctly?

You can achieve the "no show" behavior if you set isShown=false and event="none" or by wrapping your tooltip in an {{#if}} block. @jliuzen how would you do this if you wanted to disable z-help-text-popover for mobile users? Assuming you had a boolean for isMobile.

I'm a little hesitant to introduce this because there are existing ways to get the same behavior and with more options comes more complexity. From a technical point of view this PR looks good though. Can you explain a little more about why a disabled property is the best option?

@a15n
Copy link
Contributor

a15n commented Nov 30, 2016

@aaminev would this be useful in the scenario when there is no tooltip text? You could do something like...

{{#tooltip-on-element disabled=(not tooltipText.length)}}
  {{tooltipText}}
{{/tooltip-on-element}}

This way you could disable a tooltip by explicitly depending on the length of the string.

@a15n
Copy link
Contributor

a15n commented Nov 30, 2016

@knownasilya also thanks for your work to add LTS support! I definitely think that's a great idea but I think it should be done in a separate PR. And also I'd prefer that we keep master green so we'd need to add 2.1.0 to the list of allow_failures until the delay test is fixed.

@knownasilya
Copy link
Author

knownasilya commented Nov 30, 2016

Maybe this is too big of a feature for something that could be replaced by a wrapper.. e.g.

{{#desktop-tooltip}}
  My Text
{{/desktop-tooltip}}

which just wraps the tooltip in an {{#if.

@a15n
Copy link
Contributor

a15n commented Dec 10, 2016

Agreed, I think the ideal way would be to create you're own wrapper.

@a15n a15n closed this Dec 10, 2016
@sir-dunxalot
Copy link
Owner

Another solution could be to set event='none' in scenarios where you don't want to render the tooltip.

@a15n a15n mentioned this pull request Dec 15, 2016
@knownasilya
Copy link
Author

knownasilya commented Dec 20, 2016

@sir-dunxalot so change it to none and then change it back when you want it to show? Because wrapping it in a component doesn't really work I get no behavior unless I set tagName: '' and then I get errors:

Uncaught DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.
    at Object.clear (http://stocktonca.mg.dev/assets/vendor.js:59330:20)
    at UpdatableBlockTracker.reset (http://stocktonca.mg.dev/assets/vendor.js:59667:56)
    at TryOpcode.handleException (http://stocktonca.mg.dev/assets/vendor.js:68468:113)
    at UpdatingVMFrame.handleException (http://stocktonca.mg.dev/assets/vendor.js:68650:35)
    at UpdatingVM._throw [as throw] (http://stocktonca.mg.dev/assets/vendor.js:68363:37)
    at Assert.evaluate (http://stocktonca.mg.dev/assets/vendor.js:63745:25)
    at UpdatingVM.execute (http://stocktonca.mg.dev/assets/vendor.js:68350:24)
    at RenderResult.rerender (http://stocktonca.mg.dev/assets/vendor.js:68289:16)
    at RootState._this.render (http://stocktonca.mg.dev/assets/vendor.js:25879:18)
    at runInTransaction (http://stocktonca.mg.dev/assets/vendor.js:36838:28)

My code looks like so:

desktop-tooltip.hbs

{{#unless media.isMobile}}
  {{#tooltip-on-element side=side delay=delay duration=duration}}
    {{yield}}
  {{/tooltip-on-element}}
{{/unless}}

desktop-tooltip.js

import Ember from 'ember';
  
export default Ember.Component.extend({
  tagName: '',
  side: 'bottom',
  delay: 750
});

The error occurs when isMobile is true and the tooltip is removed.

@knownasilya
Copy link
Author

Related issue: yapplabs/ember-tether#35 so this doesn't work with 2.10 if you put it in an {{#if.

@knownasilya
Copy link
Author

knownasilya commented Dec 20, 2016

So the workaround for that would be to wrap {{#tooltip-on-element with a <div>, but this doesn't work for me because then the tooltip doesn't show since it's on the wrong element. Looks like disabled is necessary after all, or to have to use target..

@SirZach
Copy link

SirZach commented Apr 13, 2017

@knownasilya was this thread continued anywhere else or is it not addressed? I see yapplabs/ember-tether#35 is still open which is blocking the upgrade to 2.11 at the moment

@knownasilya
Copy link
Author

knownasilya commented Apr 13, 2017

It hasn't continued. Basically, I did a wrapper component like so:

{{#unless media.isMobile}}
  <div>
    {{#tooltip-on-element side=side delay=delay duration=duration}}
      {{yield}}
    {{/tooltip-on-element}}
  </div>
{{/unless}}

@SirZach
Copy link

SirZach commented Apr 13, 2017

@knownasilya did you have a solution for {{tooltip-on-component}}?

@knownasilya
Copy link
Author

I didn't have that requirement. I think this PR would have to be completed to support that.

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.

None yet

4 participants