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 Request: Support !! in bindings #3188

Closed
opus1269 opened this issue Dec 11, 2015 · 3 comments
Closed

Feature Request: Support !! in bindings #3188

opus1269 opened this issue Dec 11, 2015 · 3 comments

Comments

@opus1269
Copy link

This makes for a slick way to bind to boolean attributes with non-boolean properties that can be truthy or falsey

For instance, a possible use case from iron-image

       /**
         * Sets a sizing option for the image.  Valid values are `contain` (full
         * aspect ratio of the image is contained within the element and
         * letterboxed) or `cover` (image is cropped in order to fully cover the
         * bounds of the element), or `null` (default: image takes natural size).
         */
        sizing: {
          type: String,
          value: null
        },

...

    <div id="backdrop" hidden$="[[!sizing]]"></div>
    <img id="img" role="none" hidden$="[[!!sizing]]">

Otherwise, you need to put it in a computed binding.

ht to @bicknellr for the idea.

@Jamtis
Copy link

Jamtis commented Dec 12, 2015

Can you please provide a use-case where the hidden tag must be true instead of the sizingvalue.
When I see 'hiding' I think about CSS selectors that apply some displaystyles, however div[hidden] {} would also match <div hidden$="[[sizing]]">.

@TimvdLippe
Copy link
Contributor

This has been previously requested in #2343 . The official response was:

We're not very interested in expanding the vocabulary of expressions right now.
You can always make a computed function that applies a boolean pass over the input:

<my-element attr$="[[bool(numeric_prop)]]"></my-element>
  bool: function(prop) {
    return !!prop;
  }

@opus1269
Copy link
Author

@JeremybellEU Thanks for the info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants