Skip to content

Commit 7d0cd6c

Browse files
authored
fix: fixed combobox mode not show 0 value (#968)
* fix: fixed combobox mode not show 0 value * fix: combo mode no value just fixed 0 value * fix: format * fix: take review suggestion and add comment
1 parent 8932c56 commit 7d0cd6c

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/Select.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import OptGroup from './OptGroup';
5050
import Option from './Option';
5151
import OptionList from './OptionList';
5252
import SelectContext from './SelectContext';
53-
import { hasValue, toArray } from './utils/commonUtil';
53+
import { hasValue, isComboNoValue, toArray } from './utils/commonUtil';
5454
import { fillFieldNames, flattenOptions, injectPropsWithOption } from './utils/valueUtil';
5555
import warningProps, { warningNullOptions } from './utils/warningPropsUtil';
5656

@@ -307,8 +307,8 @@ const Select = React.forwardRef(
307307
const rawLabeledValues = React.useMemo(() => {
308308
const values = convert2LabelValues(internalValue);
309309

310-
// combobox no need save value when it's no value
311-
if (mode === 'combobox' && !values[0]?.value) {
310+
// combobox no need save value when it's no value (exclude value equal 0)
311+
if (mode === 'combobox' && isComboNoValue(values[0]?.value)) {
312312
return [];
313313
}
314314

src/utils/commonUtil.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ export function hasValue(value) {
1717
return value !== undefined && value !== null;
1818
}
1919

20+
/** combo mode no value judgment function */
21+
export function isComboNoValue(value) {
22+
return !value && value !== 0;
23+
}
24+
2025
function isTitleType(title: any) {
2126
return ['string', 'number'].includes(typeof title);
2227
}

tests/Combobox.test.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,4 +600,10 @@ describe('Select.Combobox', () => {
600600

601601
jest.useRealTimers();
602602
});
603+
604+
// https://github.com/ant-design/ant-design/issues/43936
605+
it('combobox mode not show 0 value', () => {
606+
const wrapper = mount(<Select mode="combobox" value={0} />);
607+
expect(wrapper.find('input').props().value).toBe('0');
608+
});
603609
});

0 commit comments

Comments
 (0)