shipshapecode / shepherd

Guide your users through a tour of your app
https://shepherdjs.dev
Other
13k stars 645 forks source link

How to add data attributes on cancel Icon? #2036

Open didaquis opened 2 years ago

didaquis commented 2 years ago

Hello.

I would like to know if there is a way to add a data attribute on the cancel tour icon.

In the documentation, it indicates that these are the only possible options:

Captura de pantalla 2022-08-24 a las 8 54 01

Using this options...

cancelIcon: {
        enabled: true,
        label: 'foo'
 }

... you will get this:

<button aria-label="foo" class="shepherd-cancel-icon" type="button">
       <span aria-hidden="true">×</span>
</button>

But I would like to get something like this:

<button aria-label="foo" class="shepherd-cancel-icon" type="button" data-whatever="some-value">
       <span aria-hidden="true">×</span>
</button>

Is there any way to add this data-whatever="some-value" ?

RobbieTheWagner commented 2 years ago

Currently, no. This is the component for it https://github.com/shipshapecode/shepherd/blob/master/src/js/components/shepherd-cancel-icon.svelte

I suppose we could add the ability to pass any arbitrary attributes down to components. Not sure if that would be good to do or not.

didaquis commented 2 years ago

Adding those attributes can be useful for selectors. For example: https://docs.cypress.io/guides/references/best-practices#Selecting-Elements

This is useful in cases where the value of the “aria-label” changes dynamically. Adding a non-dynamic attribute can help you get a proper selector for e2e testing.

RobbieTheWagner commented 2 years ago

@didaquis if you have a solution in mind that works for your use case, could you please open a PR?

RobbieTheWagner commented 2 years ago

This was requested for buttons here as well https://github.com/shipshapecode/angular-shepherd/issues/623 so perhaps we could make the components pass any arbitrary attributes down to the elements?

didaquis commented 2 years ago

In my opinion, will be cool something like this:

This code...

cancelIcon: {
        enabled: true,
        label: 'close the tour', 
        dataAttributes: [
            { 
                id: 'foo', value: 'someData'
            },
            { 
                id: 'bar', value: '1234'
            },
        ]
      },

... will produce this

<button aria-label="close the tour" data-foo="someData" data-bar="1234" class="shepherd-cancel-icon" type="button"><span aria-hidden="true">×</span></button>
didaquis commented 2 years ago

@didaquis if you have a solution in mind that works for your use case, could you please open a PR?

To be honest, I don't have enough time right now to investigate how the library works inside and implement the functionality. Sorry

RobbieTheWagner commented 2 years ago

I would suggest allowing passing any arbitrary attributes. Something like:

attributes: [
  'data-foo-bar': 123,
  class: 'foo',
  style: 'color: red'
]

@EmNicholson93 could you work on supporting this please?

Steezli commented 2 years ago

@rwwagner90 happy to, I was already thinking it'd be a good one to tackle as I think it'll apply to a few existing issues or at least point me in the same direction as a few other issues.

didaquis commented 1 year ago

hi @Steezli

Is there any news related to this issue?