Comments (3)
The same behaviour can be found in other input fields. The serializedValue()
is used to update the serializedValue every time the value changes, so it is part of our core value behaviour. Changing this is will be hard, since it will influence a lot of code.
What you could do is to set the serializedValue
only once in firstUpdated()
, and not on every paint.
from lion.
I've figured out a workaround until fixed. Seems to work without any issues for me.
Given that it consistently defaults to ".serializedValue," we can ensure that this value stays current whenever a modification occurs. While not ideal, it serves the purpose for now.
static properties = {
count: { type: Number },
currentValue : {type: String}
};
constructor() {
super();
this.count = 0;
this.currentValue = 'diplodocus';
}
render() {
return html` <lion-form
name="dinosaurs"
.serializedValue=${{ favoriteDinosaur: this.currentValue }}
>
<form>
<lion-radio-group
name="favoriteDinosaur"
label="What is your favourite dinosaur ${this.count}?"
@model-value-changed=${(e) => {
this.currentValue = e.target.modelValue;
this.count += 1;
}}
>
<lion-radio
label="Allosaurus"
.choiceValue=${'allosaurus'}
></lion-radio>
<lion-radio
label="Brontosaurus"
.choiceValue=${'brontosaurus'}
></lion-radio>
<lion-radio
label="Diplodocus"
.choiceValue=${'diplodocus'}
></lion-radio>
</lion-radio-group>
</form>
</lion-form>`;
from lion.
I believe I've found the cause of this issue.
in ChoiceGroupMixin.js there is the following function.
/**
* @param {ChoiceInputHost} el
* @param {string} val
*/
const checkCondition = (el, val) => el.serializedValue.value === val;
if (this.__isInitialSerializedValue) {
this.registrationComplete.then(() => {
this.__isInitialSerializedValue = false;
this._setCheckedElements(value, checkCondition);
this.requestUpdate('serializedValue');
});
} else {
this._setCheckedElements(value, checkCondition);
this.requestUpdate('serializedValue');
}
}
Here's whats happening:
- If statement succesfully runs, and sets the checked value to
value
. - Right after this function runs again, but since
this.__isInitialSerializedValue
was set to false it then goes to the else statement. and sets the checked value once again, which is fine, but (i believe) unnecessary. - Every time we try to select a different radio option
set serializedValue(value)
gets invoked for some reason. The value briefly changes to the desired one, but then it immediately changes back to the initial serializedValue.
I am not sure what the desired result was of this specific part :
this._setCheckedElements(value, checkCondition);
this.requestUpdate('serializedValue');
}
So i'm not confident in proposing a solution yet. Although i did try a few things that seem to work and passed the tests.
One is simply removing this._setCheckedElements(value, checkCondition);
in the else block. Another was instead of passing value
to this._setCheckedElements
inside the else block, we could instead pass this.modelValue
as an argument. e.g. this._setCheckedElements(this.modelValue, checkCondition);
from lion.
Related Issues (20)
- [LionCombobox] dispatches model-value-changed with stale modelValue after clear() HOT 1
- [FormatMixin] formatting skipped on first render when defined after modelValue
- Combobox does not reset modelValue and textbox value on reset
- Combobox doesn't display modelValue when autocomplete mode is set to "list" or "none"
- Not able to do npm install after cloning the repo HOT 1
- @lion/ajax has a problem with overwriting pre-existing headers in fetchJson
- (React) checkbox group and checkbox do not render HOT 1
- renderLitAsNode breaks when using @webcomponents/scoped-custom-element-registry HOT 2
- Migrating to @lion/ui 0.52 from @lion/core HOT 1
- select-rich when [read-only] it still works with keyboard interaction HOT 1
- [@lion/ui]: Depending on @open-wc/scoped-elements ^2.1.4 causes "Multiple versions of Lit loaded" HOT 3
- [@lion/ui/localize.js] parseNumber('--42') is parsed as NaN HOT 9
- [LionInputAmount] uses `NaN` where `Unparseable` would be preferred HOT 3
- NPM library does not have the latest code HOT 2
- Lion-input-file should revoke created object URL's or dev should be warned that they might need to revoke the URL
- Console error on Listbox validation HOT 1
- [LionSwitch]: Clicking on label tiggers checked-changed twice HOT 3
- Buttons Do Not Change Cursor Type HOT 4
- [consistency] clean setup/teardown of external/slotted elements
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lion.