Skip to content

Commit

Permalink
[BUGFIX] Empêcher la propagation des événements dans tous les enfants…
Browse files Browse the repository at this point in the history
… sur la Tooltip (PIX-6149)
  • Loading branch information
github-actions[bot] authored Oct 28, 2022
2 parents 215290b + 1ad198a commit caf2a7d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
6 changes: 4 additions & 2 deletions addon/components/pix-tooltip.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
class="pix-tooltip"
{{on-escape-action this.hideTooltip}}
{{on "mouseover" this.showTooltip}}
{{on "mouseout" this.hideTooltipOnMouseOut}}
{{on "mouseleave" this.hideTooltipOnMouseOut}}
{{on "focusin" this.showTooltip}}
{{on "focusout" this.hideTooltip}}
...attributes
>
{{#if (has-block "triggerElement")}}
{{yield to="triggerElement"}}
<div class={{if this.isVisible "pix-tooltip--visible" ""}}>
{{yield to="triggerElement"}}
</div>
{{/if}}

{{#if (has-block "tooltip")}}
Expand Down
13 changes: 8 additions & 5 deletions addon/components/pix-tooltip.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';

export default class PixTooltip extends Component {
@tracked isVisible = false;

get position() {
const correctsPosition = [
'top',
Expand All @@ -21,18 +24,18 @@ export default class PixTooltip extends Component {
}

@action
showTooltip(event) {
event.target.classList.add('pix-tooltip--visible');
showTooltip() {
this.isVisible = true;
}

@action
hideTooltip(event) {
event.target.classList.remove('pix-tooltip--visible');
hideTooltip() {
this.isVisible = false;
}

@action
hideTooltipOnMouseOut(event) {
const isFocused = document.activeElement === event.target;
const isFocused = event.target.contains(document.activeElement);

if (isFocused) {
return;
Expand Down
1 change: 1 addition & 0 deletions addon/styles/_pix-tooltip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
display: flex;
justify-content: center;
align-items: center;

}

.pix-tooltip--visible {
Expand Down
27 changes: 27 additions & 0 deletions app/stories/pix-tooltip.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,27 @@ const TemplateWithHTMLElement = (args) => {
};
};

const TemplateWithIconElement = (args) => {
return {
template: hbs`
<PixTooltip
@id={{this.id}}
@isInline=true>
<:triggerElement>
<button style='padding:0; margin-left:4px; line-height:0;'>
<FaIcon class="external-link" @icon="up-right-from-square" />
</button>
</:triggerElement>
<:tooltip>
{{this.text}}
</:tooltip>
</PixTooltip>
`,
context: args,
};
};

export const Default = Template.bind({});
Default.args = {
text: 'Hello World',
Expand Down Expand Up @@ -113,6 +134,12 @@ WithHTML.args = {
label: 'À survoler pour voir la tooltip',
};

export const WithIcon = TemplateWithIconElement.bind({});
Default.args = {
text: 'Hello World',
label: 'À survoler pour voir la tooltip',
};

export const argTypes = {
id: {
name: 'id',
Expand Down
1 change: 1 addition & 0 deletions app/stories/pix-tooltip.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Infobulle en position `top`, fond sombre (par défaut).

<Canvas>
<Story name="Default" story={stories.Default} height={200} />
<Story name="WithIcon" story={stories.WithIcon} height={200} />
</Canvas>

## Is Light
Expand Down

0 comments on commit caf2a7d

Please sign in to comment.