question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Component element attribute?

See original GitHub issue

Hello Ben! Thank you for the great work on Sprig. 🏆

Question

I wanted to ask if it is possible to set another HTML element than a <div> for the (surrounding) Sprig component element?

Additional context

I want to use a regular old <ol> list and add list item elements (load more) to the end of it. The Sprig div is already there, it is just not the right parent element for my list items. Adding an ordered list element breaks the list, as the div ends up inside the <ol> list element.

Is there a different (better) semantic and accessible approach to have the component div, then the ordered list item followed by the list items?

At the end I want to combine it with a filter component as well. The load more and filter component working together. I have it work, but the HTML is not right at the moment.

Example

From this:

<div id="component-tblode" class="sprig-component">
    <ol class="listing">
       <li class="list-element">
            Lorem ipsum dolor sit amet…
       </li>
    </ol>
</div>

to this:

<ol id="component-tblode" class="sprig-component listing">
   <li class="list-element">
        Lorem ipsum dolor sit amet…
   </li>
</ol>

using something like this:

{{ sprig('_components/listing', {}, {
    '_element': 'ol',
    'id': 'listing-component',
    …
}) }}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:10

github_iconTop GitHub Comments

1reaction
ghostcommented, Oct 2, 2020

@bencroker thank you. 🏆

It works, but you are right. It’s a bit “messy” for such a use case, hence my question to make the <div> the <ol> in the first place, so that there would not be an extra element to take care of like in this case. I can understand though that you are not very keen on making the element an available attribute. In htmx it would not even be a problem, as you put the htmx attributes to closest relevant element.

1reaction
bencrokercommented, Oct 1, 2020

Normally yes, however if the button is inside a sprig.isInclude condition, as it is above, then it will be rendered once and only once.

This works for me provided a Javascript variable called offset exists:

s-vars="offset: offset += {{ limit }}"
Read more comments on GitHub >

github_iconTop Results From Across the Web

Using custom elements - Web Components | MDN
The controller of custom elements on a web document is the CustomElementRegistry object — this object allows you to register a custom element...
Read more >
Using Attributes and Properties in Custom Elements
Global attributes are attributes common to all HTML elements; they can be used on all elements, though they may have no effect on...
Read more >
How to get an attribute value in Angular's components and ...
In this tutorial, we will explore all the ways to read HTML attribute values passed in the component or directive. Reading HTML Attributes....
Read more >
Knowledge: Attributes and properties - Open Web Components
Attributes are key value pairs defined in HTML on an element: ... Many web component libraries allow you to configure this syncing behavior...
Read more >
Use Angular Component as Element, Attribute, and Class
Components are building blocks of any Angular application. Most commonly Angular components exist as custom markup elements in the template.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found