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

Feature: bind to style with object, array and string merging/override support #236

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,24 @@ For example:

In this example, the "hidden" class will only be applied when the value of the `foo` data attribute is `true`.

**`x-bind` for style attributes**

`x-bind` behaves a little differently when binding to the `style` attribute.

For styles, you pass in an object who's keys are style names, and values are either CSS property values (strings) or falsy. If the value is falsy the style will not be applied.

For example:
`<div x-bind:class="{ display: foo && 'inline', fontSize: 20 + 'px' }"></div>`

In this example, the "display" style will only be applied when the value of the `foo` data attribute is `true`.

`style` bindings also support arrays and will merge/override rules.

For example:
`<div style="display: inline" x-bind:style="['display: hidden; width: 200px;', 'height: 20px;']"></div>`

In this example, the "display" style will be set to "hidden", "width" will be "200px" and height will be "20px"

**`x-bind` for boolean attributes**

`x-bind` supports boolean attributes in the same way that value attributes, using a variable as the condition or any JavaScript expression that resolves to `true` or `false`.
Expand Down
Loading