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

Pass additional properties to a and span elements #15

Closed
iloveip opened this issue Jun 8, 2020 · 9 comments
Closed

Pass additional properties to a and span elements #15

iloveip opened this issue Jun 8, 2020 · 9 comments
Labels
💪 phase/solved Post is done 🦋 type/enhancement This is great to have

Comments

@iloveip
Copy link
Contributor

iloveip commented Jun 8, 2020

I would like to be able to pass additional properties to the link itself and the span element, like className (for both elements) and role: 'img' for span.

At the moment I had to add another span inside the given span to do this:
content: h('span', {role: 'img', class: 'anticon'}, s('svg',...)). And I can't style the link, as there is no way to pass className to it.

@iloveip iloveip added 🙉 open/needs-info This needs some more info 🦋 type/enhancement This is great to have labels Jun 8, 2020
@wooorm
Copy link
Member

wooorm commented Jun 8, 2020

👋

Could you tell us more about the higher-level thing you want to achieve? Maybe that’s better done in a custom-made plugin?

@iloveip
Copy link
Contributor Author

iloveip commented Jun 8, 2020

I need to have something like this:

<a href="link_url" target="_blank" rel="nofollow noopener noreferrer" class="external">link_title
  <span role="img" class="anticon">
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="64 64 896 896" focusable="false" width="1em" height="1em" fill="currentColor" aria-hidden="true">
      <path></path>
    </svg>
  </span>
</a>

So I need to be able to pass className to a and to span. I also need to pass role="img" to span.

At the moment I have the following for the content:

content: h('span', {role: 'img', class: 'anticon'}, s('svg', {xmlns: 'http://www.w3.org/2000/svg', viewBox: '64 64 896 896', focusable: 'false', width: '1em', height: '1em', fill: 'currentColor', ariaHidden: 'true'}, s('path', {d: ''})))

But without classes and the span is wrapped in another span

@wooorm
Copy link
Member

wooorm commented Jun 8, 2020

Might your case also in the end need for example classes or icons for local/internal links (#heading or /same/site)?

@iloveip
Copy link
Contributor Author

iloveip commented Jun 8, 2020

No, we use icons only for external links. Internal links are managed by gatsby-plugin-catch-links.

@wooorm
Copy link
Member

wooorm commented Jun 8, 2020

Would the CSS selector a[rel] or a[target] be a potential solution to use instead of the class?

@iloveip
Copy link
Contributor Author

iloveip commented Jun 8, 2020

Yes, a[rel] works.

@wooorm
Copy link
Member

wooorm commented Jun 8, 2020

Ah great!!

For the properties, that can be done! Would you be interested in working on a PR for that? Something like:

  contentProperties = settings.contentProperties || {}

  // ...

  data: {hName: 'span', hProperties: extend(true, contentProperties), hChildren: extend(true, content)}

In index.js?

@iloveip
Copy link
Contributor Author

iloveip commented Jun 8, 2020

Yes, sure, I've created the PR above. But I'm new to programming, so I don't really know what's the right way to do it.

@wooorm
Copy link
Member

wooorm commented Jun 8, 2020

Closed by GH-16.

@wooorm wooorm closed this as completed Jun 8, 2020
@wooorm wooorm added ⛵️ status/released 🦋 type/enhancement This is great to have and removed 🙉 open/needs-info This needs some more info 🦋 type/enhancement This is great to have labels Jul 23, 2020
@wooorm wooorm added the 💪 phase/solved Post is done label Aug 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💪 phase/solved Post is done 🦋 type/enhancement This is great to have
Development

No branches or pull requests

2 participants