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

How to add data attributes on cancel Icon? #2036

Open
didaquis opened this issue Aug 24, 2022 · 9 comments
Open

How to add data attributes on cancel Icon? #2036

didaquis opened this issue Aug 24, 2022 · 9 comments
Assignees

Comments

@didaquis
Copy link
Contributor

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
Copy link
Member

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
Copy link
Contributor Author

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
Copy link
Member

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

@RobbieTheWagner
Copy link
Member

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

@didaquis
Copy link
Contributor Author

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
Copy link
Contributor Author

@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
Copy link
Member

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
Copy link
Contributor

Steezli commented Aug 31, 2022

@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.

@Steezli Steezli self-assigned this Aug 31, 2022
@didaquis
Copy link
Contributor Author

hi @Steezli

Is there any news related to this issue?

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

No branches or pull requests

3 participants