Skip to content

Commit

Permalink
fix(react): prevent clearing selectfield when disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
dackmin committed Sep 29, 2022
1 parent 725f3fb commit 16025a7
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
3 changes: 2 additions & 1 deletion packages/react/lib/SelectField/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ const SelectField = forwardRef(({
const onClear = e => {
e.stopPropagation();

if (!clearable) {
if (!clearable || disabled) {
return;
}

Expand Down Expand Up @@ -415,6 +415,7 @@ const SelectField = forwardRef(({
onChange={onSearchInputChange}
ref={searchInputRef}
autoFocus={autoFocus}
disabled={disabled}
onFocus={onFocus_}
onBlur={onBlur_}
onKeyPress={onKeyPress_}
Expand Down
10 changes: 10 additions & 0 deletions packages/react/lib/SelectField/index.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ export const multiple = () => (
/>
);

export const disabled = () => (
<SelectField
placeholder="Type a name"
multiple={true}
value={['Item 1', 'Item 2']}
disabled={true}
options={[{ title: 'Group 1', options: ['Item 1', 'Item 2'] }, 'Item 3']}
/>
);

export const asyncSearch = () => (
<SelectField
placeholder="Type a name"
Expand Down
32 changes: 26 additions & 6 deletions packages/react/lib/SelectField/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -337,19 +337,39 @@ exports[`<SelectField /> should render multiple values 1`] = `
<span>
Item 1
</span>
<a
class="delete"
/>
<svg
class="junipero icon remove"
height="10"
viewBox="0 0 9 10"
width="10"
>
<path
d="M8 1.5L1 8.5"
/>
<path
d="M1 1.5L8 8.5"
/>
</svg>
</span>
<span
class="junipero tag info"
>
<span>
Item 2
</span>
<a
class="delete"
/>
<svg
class="junipero icon remove"
height="10"
viewBox="0 0 9 10"
width="10"
>
<path
d="M8 1.5L1 8.5"
/>
<path
d="M1 1.5L8 8.5"
/>
</svg>
</span>
<input
placeholder="Name"
Expand Down
7 changes: 7 additions & 0 deletions packages/theme/lib/SelectField.sass
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
display: inline-flex
width: 250px

&.disabled
opacity: .5

.field
&, &.icon.remove, & .icons .icon.remove
cursor: default

&:focus-within,
&.opened
--border-color: var(--main-color)
Expand Down

0 comments on commit 16025a7

Please sign in to comment.