Conversation
|
Hmm, what is the use case for this? I'm guessing on <DropdownTrigger>
<Button as_child=true />
</DropdownTrigger>right? Are you using this anywhere? If so can you provide an example of how you're using it? If this is what I think it is then I'd love to have it because right now all trigger components are just buttons, which is fine most of the time until it's not. Or, as I just realized before submitting this, I think |
|
Yes, but as_child should be applied to the parent element. It then renders only the child element and attaches the parent’s attributes to it. So, the appearance and functionality of the parent are merged with the child, without rendering the parent element itself. My own usecase was this: <Button as_child=true>
<label for="file" class="cursor-default">
<input type="file" id="file" class="hidden" />
{icon!(LuUpload)}
"Upload File"
</label>
</Button>Which is rendered like this: <label class="cursor-default singlestage-btn-primary" for="file">
<input type="file" id="file" class="hidden">
<svg class="" style="" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" stroke="currentColor" fill="none"><path d="M12 3v12"></path>
<path d="m17 8-5-5-5 5"></path>
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path><!---->
</svg>
Upload File
</label>I found a lot of examples in the shadcn blocks page: |
|
I added as_child to some triggers:
|
|
I tested this syntax: <Button as_child=true let:class>
<CustomChild class=class />
</Button>It works and looks nice. we can even expose more than just the |
Maybe we can only affect the inner element (the The CSS will have to change for sure (like
I'm not sure what you mean specifically about "provide defaults in the website" but we should be able to just conditionally include the class depending on if
At the end of the day we have quite a bit of freedom to modify implementation code as long as the API and behavior remain the same, or similar. We can break things if we really have to. This is a feature I would like to have, whether it matches Radix/shadcn or not. Like I said above, if we have to bend things to fit I would rather bend the new feature than break the existing API. Within reason.
|
|
https://www.w3.org/TR/2012/WD-html5-20120329/the-button-element.html#the-button-element buttons actually support lots of children: "Phrasing content, but there must be no interactive content descendant." |
Yes, that probably works most of the time, but I think when users use as_child, they assume there is no longer an inner element. As a result, they write CSS selectors targeting the original structure, which would break.
Totally agree.
I mean something like BaseUI. Unstyled by default, but the website explicitly provides ready-to-use styles (via both Tailwind and CSS modules) that users can copy. This way, there’s no complexity in tweaking styles, everything lives in user land.
Exactly. Right now, these classes are implementation details, but you can expose them as official default styles. Then users can explicitly apply them, tweak them, or write their own.
I understand, but since this library is still in its early stages, you can make bigger changes now. Breaking changes now are far better than being stuck with a problematic design decision a year from now.
I agree. What about the twin component idea? (<ButtonSlot/>) |
|
let is better than Slot if neither is not an option |
|
Also if a user wants to do their own styles they can just choose to not use |
This is not a ready-to-merge PR. I just had an idea and wanted to share it.
I implemented a very naive
as_childmechanism in the Button component, which passes the children directly without the button element.This probably comes with a lot of edge cases that I haven't tested.
In comparison to Radix UI, in all conflicts, the parent wins, except for classes, which will merge because of the new
PatchClasstype I declared (it probably has room for further optimization and improvement).