Skip to content
Open
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
2 changes: 2 additions & 0 deletions packages/react-widgets/src/Combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ const ComboboxImpl: Combobox = React.forwardRef(function Combobox<TDataItem>(
data: string | TDataItem,
originalEvent: React.SyntheticEvent,
) => {
if (isDisabled) return

toggle.close()
shouldFilter.current = false

Expand Down
2 changes: 2 additions & 0 deletions packages/react-widgets/src/Multiselect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,8 @@ const Multiselect: Multiselect = React.forwardRef(function Multiselect<
dataItem: TDataItem | undefined,
originalEvent: React.SyntheticEvent,
) => {
if (isDisabled) return

if (dataItem === undefined) return

originalEvent.preventDefault()
Expand Down
28 changes: 28 additions & 0 deletions packages/react-widgets/test/Combobox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,34 @@ describe('Combobox', function () {
{ label: 'suzy smith', id: 3 },
]

it('ignores option clicks after the open widget becomes disabled', () => {
const onChange = sinon.spy()
const onSelect = sinon.spy()
const widget = mount(
<Combobox
data={['Apple', 'Orange']}
defaultValue="Apple"
onChange={onChange}
onSelect={onSelect}
open
/>,
)

expect(
widget
.find('[role="option"]')
.someWhere((option) => option.text() === 'Orange'),
).to.equal(true)
widget.setProps({ disabled: true })
widget
.find('[role="option"]')
.filterWhere((option) => option.text() === 'Orange')
.simulate('click')

expect(onChange.called).to.equal(false)
expect(onSelect.called).to.equal(false)
})

it('should set initial values', function () {
mount(<Combobox value={'hello'} onChange={() => {}} />)
.find('input.rw-input')
Expand Down
28 changes: 28 additions & 0 deletions packages/react-widgets/test/Multiselect-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,34 @@ describe('Multiselect', function () {
{ label: 'pat', id: 2 },
]

it('ignores option clicks after the open widget becomes disabled', () => {
const onChange = sinon.spy()
const onSelect = sinon.spy()
const widget = mount(
<Multiselect
data={['Apple', 'Orange']}
defaultValue={['Apple']}
onChange={onChange}
onSelect={onSelect}
open
/>,
)

expect(
widget
.find('[role="option"]')
.someWhere((option) => option.text() === 'Orange'),
).to.equal(true)
widget.setProps({ disabled: true })
widget
.find('[role="option"]')
.filterWhere((option) => option.text() === 'Orange')
.simulate('click')

expect(onChange.called).to.equal(false)
expect(onSelect.called).to.equal(false)
})

it('should set initial values', function () {
mount(<Multiselect value={['hello']} onChange={() => {}} />)
.find(MultiselectTag)
Expand Down