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

Update Tooltip.vue #97

Open
wants to merge 5 commits into
base: v3
Choose a base branch
from
Open
Changes from 1 commit
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
79 changes: 50 additions & 29 deletions src/components/Tooltip/Tooltip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@
<div class="tooltip">
<div ref="target" class="target" @mouseenter="onMouseEnter"
@mouseleave="onMouseLeave">
<slot/>
<slot />
<transition name="fade">
<Popper v-if="show" ref="popper" :transition-delay="0"
:boundaries-element="boundariesElement"
:target-element="$refs.target" :placement="placement" :offset="offset">
<span ref="label" class="label" :disabled="disabled" @mouseenter="onMouseEnter"
@mouseleave="onMouseLeave">
<slot name="label"></slot>
</span>
<span v-if=label ref="label" class="label no-click" :disabled="disabled">
Copy link

Choose a reason for hiding this comment

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

There are two tooltips, one being empty.

On Storybook (http://localhost:9001/?path=/story/tooltip--tooltip):
image
image

Copy link
Author

Choose a reason for hiding this comment

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

fixed

{{ label }}
</span>
</Popper>
</transition>
</div>
<transition name="fade">
<Popper v-if="show" ref="popper" :transition-delay="300"
:boundaries-element="boundariesElement"
:target-element="$refs.target" :placement="placement" :offset="offset">
<span ref="label" class="label" :disabled="disabled">{{ label }}</span>
</Popper>
</transition>
</div>
</template>

Expand All @@ -23,48 +29,60 @@
props: {
label: {
type: String,
required: true
},
placement: {
type: String,
default: 'bottom'
default: 'bottom',
},
disabled: {
type: Boolean,
default: false
default: false,
},
offset: {
type: String,
default: '0,5'
default: '0,5',
},
appendToBody: {
type: Boolean,
default: false
default: false,
},
boundariesElement: {
type: String,
default: 'viewport'
}
default: 'viewport',
},
delay: {
type: Number,
default: 0,
Copy link

Choose a reason for hiding this comment

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

I would say to go with the default 300ms, as in Atlassian Design System, but I see the props of this component don't actually match the ADS 🤷‍♂️ so imo go with whatever you want.

Copy link
Author

Choose a reason for hiding this comment

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

I don't think we should change the default behaviour

},
},
data() {
return {
show: false
mouseEntered: false,
show: false,
};
},
methods: {
onMouseEnter() {
this.show = true;
if (this.appendToBody) {
this.$nextTick(() => {
this.append();
});
}
this.mouseEntered = true;
setTimeout(() => {
if (!this.mouseEntered) return;
Copy link

Choose a reason for hiding this comment

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

This is a problem only for bigger delays so maybe we can ignore it.
You can for example for 5s delay:

  1. hover over the button
  2. wait 1s
  3. hover away
  4. wait 3s
  5. hover back on
  6. wait 1s
    Result: tooltip opens up after 1s from hovering on.
    You can get similar effects for closing the tooltip.

Copy link
Author

Choose a reason for hiding this comment

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

fixed

this.show = true;
if (this.appendToBody) {
this.$nextTick(() => {
this.append();
});
}
}, this.delay);
},
onMouseLeave() {
if (this.appendToBody) {
document.body.removeChild(this.$refs.label);
}
this.show = false;
this.mouseEntered = false;
setTimeout(() => {
if (this.mouseEntered) return;
if (this.appendToBody) {
document.body.removeChild(this.$refs.label);
}
this.show = false;
}, this.delay);
},
append() {
document.body.appendChild(this.$refs.label);
Expand All @@ -73,8 +91,8 @@
this.$refs.popper.update();
}
}, 0);
}
}
},
},
};
</script>

Expand All @@ -92,12 +110,15 @@
font-weight: 400;
box-shadow: 0 1px 2px 1px rgba(0, 1, 0, 0.2);
white-space: nowrap;
pointer-events: none;
border-radius: 3px;
background-color: var(--ds-background-neutral-bold, #172b4d);
color: var(--ds-text-inverse, #FFF);
}

.no-click {
pointer-events: none;
}

.fade-enter-active,
.fade-leave-active {
transition: opacity 0.3s;
Expand Down