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

fix(forms): Support undefined in toggle and button fields #2775

Merged
merged 1 commit into from
Oct 23, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,18 @@ export const ButtonsFalse = () => {
)
}

export const ButtonsUndefined = () => {
return (
<ComponentBox>
<Field.Boolean
variant="buttons"
label="Label text"
onChange={(value) => console.log('onChange', value)}
/>
</ComponentBox>
)
}

export const ButtonsRequired = () => {
return (
<ComponentBox>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ import * as Examples from './Examples'

<Examples.ButtonsFalse />

#### Button - Value undefined (no option selected)

<Examples.ButtonsUndefined />

#### Buttons - Required

<Examples.ButtonsRequired />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ function Toggle(props: Props) {
}

const isOn = value === valueOn
const isOff = value === valueOff

switch (variant) {
default:
Expand Down Expand Up @@ -134,7 +135,7 @@ function Toggle(props: Props) {
id={id}
text={textOff ?? sharedContext?.translation.Forms.booleanNo}
on_click={setOff}
variant={isOn ? 'secondary' : undefined}
variant={isOff ? undefined : 'secondary'}
disabled={disabled}
status={error ? 'error' : undefined}
/>
Expand Down
Loading