'lit-element : Bind to a boolean attribute : Issue with Internet Explorer 11
I'm using Bind to boolean attribute as mentioned in the documentation https://lit-element.polymer-project.org/guide/templates as given below.
This works fine in Chrome but for some reason not working in Internet Explorer 11. It always behaves as falsy. and doesn't add the attribute.
Is there a known issue or I'm missing something.
To simulate the scenario :
Create two custom-elements, parent and child element. Pass boolean attribute through child element boolean property and use that property to make enable disable a textbox.
Parent element
/**
* @license
* Copyright (c) 2019 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at
* http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at
* http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at
* http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at
* http://polymer.github.io/PATENTS.txt
*/
import {LitElement, html, customElement, property, css} from 'lit-element';
import './my-other-element';
/**
* An example element.
*
* @slot - This element has a slot
* @csspart button - The button
*/
@customElement('my-element')
export class MyElement extends LitElement {
static styles = css`
:host {
display: block;
border: solid 1px gray;
padding: 16px;
max-width: 800px;
}
`;
/**
* The name to say "Hello" to.
*/
@property()
name = 'World';
/**
* The number of times the button has been clicked.
*/
@property({type: Number})
count = 0;
render() {
return html`
<h1>Hello, ${this.name}!</h1>
<button @click=${this._onClick} part="button">
Click Count: ${this.count}
</button>
<my-other-element ?makeDisable="${true}"></my-other-element>
<slot></slot>
`;
}
private _onClick() {
this.count++;
}
foo(): string {
return 'foo';
}
}
declare global {
interface HTMLElementTagNameMap {
'my-element': MyElement;
}
}
Child element
/**
* @license
* Copyright (c) 2019 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at
* http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at
* http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at
* http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at
* http://polymer.github.io/PATENTS.txt
*/
import {LitElement, html, customElement, property, css} from 'lit-element';
/**
* An example element.
*
* @slot - This element has a slot
* @csspart button - The button
*/
@customElement('my-other-element')
export class MyOtherElement extends LitElement {
@property({type: Boolean}) makeDisable = false;
static styles = css`
:host {
display: block;
border: solid 1px gray;
padding: 16px;
max-width: 800px;
}
`;
/**
* The name to say "Hello" to.
*/
@property()
name = 'World';
/**
* The number of times the button has been clicked.
*/
@property({type: Number})
count = 0;
render() {
return html`
<input type="text" ?disabled="${this.makeDisable}" value="testing" />
<slot></slot>
`;
}
foo(): string {
return 'foo';
}
}
declare global {
interface HTMLElementTagNameMap {
'my-other-element': MyOtherElement;
}
}
Solution 1:[1]
In lit-element if you add a boolean value in constructor and if it is true, you cannot set false for that.
I have tried it like <input type="text" .disabled="${false}"> and it works.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | olgunyldz |
