Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: toggle default value #395

Merged
merged 1 commit into from
Feb 11, 2025
Merged

fix: toggle default value #395

merged 1 commit into from
Feb 11, 2025

Conversation

mahatoankitkumar
Copy link
Collaborator

@mahatoankitkumar mahatoankitkumar commented Jan 30, 2025

Problem

The toggle component defaults to null instead of a boolean value when initially rendered, causing unexpected behavior until user interaction occurs.

Solution

Called the onChange event handler to properly handle the initial null state, ensuring the toggle always has a valid boolean value (true/false).

@mahatoankitkumar mahatoankitkumar requested a review from a team as a code owner January 30, 2025 07:00
@Datron Datron linked an issue Jan 31, 2025 that may be closed by this pull request
}
None => view! { <Toggle value=false on_change class name/> }.into_view(),
None => {
on_change.call(Value::Bool(false));
Copy link
Collaborator

@ayushjain17 ayushjain17 Jan 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would get triggered on every re-render
this should be dealt at the moment when the type is being chosen by the user

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

}
None => view! { <Toggle value=false on_change class name/> }.into_view(),
None => {
on_change.call(Value::Bool(false));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@ayushjain17 ayushjain17 requested a review from Datron January 31, 2025 09:53
@mahatoankitkumar mahatoankitkumar force-pushed the fix/toggle branch 2 times, most recently from 612a44c to ee8e36b Compare February 3, 2025 11:54
@@ -278,6 +278,9 @@ where
) {
(Ok(schema_type), Ok(enum_variants)) => {
let input_type = InputType::from((schema_type.clone(), enum_variants));
if input_type == InputType::Toggle {
config_value_ws.set(Value::Bool(false));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is also at render time

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pending comment

@@ -278,6 +278,9 @@ where
) {
(Ok(schema_type), Ok(enum_variants)) => {
let input_type = InputType::from((schema_type.clone(), enum_variants));
if input_type == InputType::Toggle {
config_value_ws.set(Value::Bool(false));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pending comment

@ayushjain17 ayushjain17 requested a review from Datron February 7, 2025 10:30
@Datron Datron added bug Something isn't working quick win An item or task that can be quickly closed and gives us an easy win labels Feb 7, 2025
Comment on lines 254 to 269
if let (Ok(schema_type), Ok(enum_variants)) = (
SchemaType::try_from(config_schema_rs.get()),
EnumVariants::try_from(config_schema_rs.get()),
) {
if InputType::from((schema_type, enum_variants))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we not going to store it to optimise the repeated computations ?

Comment on lines 257 to 259
schema_type_ws
.set(SchemaType::try_from(type_schema.clone()));
enum_variants_ws.set(EnumVariants::try_from(type_schema));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we rather store in local variable and then set and then use the local variable in the subsequent lines

Comment on lines 257 to 268
schema_type_ws
.set(SchemaType::try_from(type_schema.clone()));
enum_variants_ws.set(EnumVariants::try_from(type_schema));
if let (Ok(schema_type), Ok(enum_variants)) = (
schema_type_rs.get(),
enum_variants_rs.get(),
) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please assign the value of schema type and enum variants to some variable and then use it set the signal and the if check.
Please refrain from setting the signal and then immediately reading from it.

@Datron Datron dismissed ShubhranshuSanjeev’s stale review February 11, 2025 13:30

Comments were resolved. Please review again

@Datron Datron merged commit e910b8f into main Feb 11, 2025
4 checks passed
@Datron Datron deleted the fix/toggle branch February 11, 2025 13:47
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working P0 quick win An item or task that can be quickly closed and gives us an easy win UI things relating to the UI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The default value for boolean toggle is not set in forms
4 participants