Skip to content

Commit

Permalink
STCOM-1373 - Selection - blank options are not selectable. (#2374)
Browse files Browse the repository at this point in the history
* Selection - switch to 'undefined' value in option-rendering conditionals rather than boolean

* log changes

(cherry picked from commit e5f1b44)
  • Loading branch information
JohnC-80 authored and zburke committed Oct 31, 2024
1 parent ff9cc38 commit 243bcfa
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* Change `Repeatable field` focus behaviour. Refs STCOM-1341.
* Fix `<Selection>` bug with option list closing when scrollbar is used. Refs STCOM-1371.
* `<Selection>` - fix bug handling empty string options/values. Refs STCOM-1373.

## [12.2.2](https://github.com/folio-org/stripes-components/tree/v12.2.2) (2024-10-30)
[Full Changelog](https://github.com/folio-org/stripes-components/compare/v12.2.1...v12.2.2)
Expand Down
4 changes: 2 additions & 2 deletions lib/Selection/Selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const getControlWidth = (control) => {
const getItemClass = (item, i, props) => {
const { value } = item;
const { selectedItem, highlightedIndex, dataOptions } = props;
if (!value) {
if (value === undefined) {
return;
}

Expand Down Expand Up @@ -260,7 +260,7 @@ const Selection = ({
const rendered = [];
for (let i = 0; i < data.length; i++) {
const item = data[i]
if (item.value) {
if (item.value !== undefined) {
const reducedIndex = reconcileReducedIndex(item, reducedListItems);
rendered.push(
<li
Expand Down
1 change: 1 addition & 0 deletions lib/Selection/stories/BasicUsage.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const hugeOptionsList = syncGenerate(3000, 0, () => {

// the dataOptions prop takes an array of objects with 'label' and 'value' keys
const countriesOptions = [
{ value: '', label: 'blank' },
{ value: 'AU', label: 'Australia' },
{ value: 'CN', label: 'China' },
{ value: 'DK', label: 'Denmark' },
Expand Down
13 changes: 12 additions & 1 deletion lib/Selection/tests/Selection-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ describe('Selection', () => {
{ value: 'test2', label: 'Option 2' },
{ value: 'sample0', label: 'Sample 0' },
{ value: 'invalid', label: 'Sample 1' },
{ value: 'sample2', label: 'Sample 2' }
{ value: 'sample2', label: 'Sample 2' },
{ value: '', label: '' },
];

const groupedOptions = [
Expand Down Expand Up @@ -281,6 +282,16 @@ describe('Selection', () => {
it('focuses the control/trigger', () => {
selection.has({ focused: true });
});

describe('clicking a "blank" option', () => {
beforeEach(async () => {
await selection.choose('');
});

it('sets control value to ""', () => {
selection.has({ value: 'select control' });
});
});
});

describe('filtering options', () => {
Expand Down

0 comments on commit 243bcfa

Please sign in to comment.