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

Proposal: Allow settings attributes on <ile-root> #150

Closed
dhruvkb opened this issue Jul 10, 2022 · 4 comments
Closed

Proposal: Allow settings attributes on <ile-root> #150

dhruvkb opened this issue Jul 10, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@dhruvkb
Copy link
Contributor

dhruvkb commented Jul 10, 2022

Is your feature request related to a problem? Please describe.
I tried to make a client-side hydrated div that grows to the size of its parent.

<div class="parent">
  <MyComponent client:load class="child">
</div>

The following CSS is applied to it.

.parent { display: flex; }
.child { flex-grow: 1; }

But the markup that is generated has the <ile-root> component in the middle of the tree which prevents the styles from working.

<div class="parent">
  <ile-root id="ile-1">
    <div class="child">Hello World!</div>
  </ile-root>
</div>

Describe the solution you'd like
It should be possible to apply some styles to the ile-root element. A hacky approach would be to support attributes like iles-class or iles-style that applies to the <ile-root> element instead of being passed down.

<div class="parent">
  <MyComponent client:load iles-class="child">
</div>

The above template should produce the below markup.

<div class="parent">
  <ile-root class="child" id="ile-1">
    <div>Hello World!</div>
  </ile-root>
</div>

Describe alternatives you've considered
Avoiding the use of styles based parent-child relationship works for now.

@ElMassimo ElMassimo added the enhancement New feature or request label Jul 11, 2022
@ElMassimo
Copy link
Owner

ElMassimo commented Jul 11, 2022

Marking it as an enhancement because .parent > * is a simple workaround for styling.


Would like to get some proposals for how to differentiate attributes for the wrapper and the inner component.

I'm leaning towards reserving the ile- prefix, as in ile-class and ile-style, which would be applied in the ile-root element:

<div class="parent">
  <MyComponent client:load ile-class="child" class="grandchild">
</div>

would result in:

<div class="parent">
  <ile-root id="ile-1" class="child">
    <div class="grandchild">Hello World!</div>
  </ile-root>
</div>

@ElMassimo ElMassimo changed the title Allow settings class/style on <ile-root> Proposal: Allow settings attributes on <ile-root> Jul 11, 2022
@joezimjs
Copy link
Contributor

Maybe allow people to use <ile-root> directly as a component in their templates and let them specify attributes directly on it, and then when compiling, if you see the ile-root component in there, just skip adding it.

Maybe?

@davidlueder
Copy link

It seems that adding class="abcd" works during development (iles dev --open) but not after generation of the static page (iles build && iles preview --open). I would really like to use this :)

@ElMassimo
Copy link
Owner

ElMassimo commented Aug 28, 2022

After considering the usages in existing sites, and assessing the trade-offs in implementation complexity, I decided to try the following approach.

The current behavior will be to apply the class attribute to the ile-root wrapper.
The inner component will still receive that class, and can choose to ignore it or apply it, as with any other prop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants