Skip to content

Conversation

@browner12
Copy link
Contributor

change the suggested x-cloak CSS to specifically only target the boolean x-cloak attribute or the attribute with an empty string value (x-cloak="").

this means we will no longer target the attribute when it has a non-empty string value (x-cloak="off").

the benefit this gives is we can conditionally disable the cloaking for elements we know will be visible immediately. this prevents a "blip in" from the hidden to visible state.

Here is a Blade example to show how it would work:

<div
    x-show="jsCondition"
    x-cloak="{{ $condition ? 'off' : '' }}"
>Alpine Rocks</div>

this works because, given these elements:

<div x-cloak></div>
<div x-cloak=""></div>
<div x-cloak="off"></div>

we get this behavior:

CSS Selector Matches
[x-cloak] all three
[x-cloak=""] first two only
[x-cloak="off"] third only

This is already possible by conditionally showing the x-cloak, but I think this solution provides a better looking code.

<div
    x-show="jsCondition"
    @if($condition)
        x-cloak
    @endif
>Alpine Rocks</div>

change the suggested `x-cloak` CSS to specifically only target the boolean `x-cloak` attribute or the attribute with an empty string value (`x-cloak=""`).

this means we will no longer target the attribute when it has a non-empty string value (`x-cloak="off"`).

the benefit this gives is we can conditionally disable the cloaking for elements we know will be visible immediately. this prevents a "blip in" from the hidden to visible state.

Here is a Blade example to show how it would work:

```blade
<div
    x-show="jsCondition"
    x-cloak="{{ $condition ? 'off' : '' }}"
>Alpine Rocks</div>
```
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

Successfully merging this pull request may close these issues.

1 participant