Skip to content

Commit

Permalink
Merge pull request #353 from supabase/fix/listbox-to-not-trigger-onse…
Browse files Browse the repository at this point in the history
…lect-if-disabled

fix: prevent on select if disabled for listbox option
  • Loading branch information
joshenlim authored May 31, 2022
2 parents 81da906 + 3bbadff commit 8777667
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/components/Listbox/Listbox2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,11 @@ function Listbox({

interface OptionProps {
id?: string
className?: string
value: any
children?: React.ReactNode
label: string
addOnBefore?: ({ active, selected }: any) => React.ReactNode
disabled?: boolean
children?: React.ReactNode
addOnBefore?: ({ active, selected }: any) => React.ReactNode
}

type addOnBefore = {
Expand All @@ -286,12 +285,11 @@ type addOnBefore = {

function SelectOption({
id,
className,
value,
children,
label,
addOnBefore,
disabled = false,
children,
addOnBefore,
}: OptionProps) {
const __styles = styleHandler('listbox')

Expand All @@ -308,7 +306,7 @@ function SelectOption({
active ? __styles.option_active : ' ',
disabled ? __styles.option_disabled : ' '
)}
onSelect={() => onChange(value)}
onSelect={() => (!disabled ? onChange(value) : {})}
>
<div className={__styles.option_inner}>
{addOnBefore && addOnBefore({ active, selected })}
Expand Down
14 changes: 14 additions & 0 deletions src/components/Listbox/SelectStyled.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ export const Default = (args: any) => (
</Listbox>
)

export const WithDisabled = (args: any) => (
<Listbox label="Default listbox">
<Listbox.Option label="Option 1" value="option-1">
Option 1
</Listbox.Option>
<Listbox.Option label="Option 2" value="option-2">
Option 2
</Listbox.Option>
<Listbox.Option disabled label="Option 3" value="option-3">
Option 3
</Listbox.Option>
</Listbox>
)

const people = [
{
value: 1,
Expand Down

0 comments on commit 8777667

Please sign in to comment.