浏览代码

fix: select is single select and renderSelectedItem, the placeholder is not displayed when the value is null #1584 (#1603)

YannLynn 2 年之前
父节点
当前提交
ce52832727
共有 2 个文件被更改,包括 38 次插入1 次删除
  1. 1 1
      packages/semi-foundation/select/foundation.ts
  2. 37 0
      packages/semi-ui/select/_story/select.stories.jsx

+ 1 - 1
packages/semi-foundation/select/foundation.ts

@@ -247,7 +247,7 @@ export default class SelectFoundation extends BaseFoundation<SelectAdapter> {
         const selectedValue = onChangeWithObject && typeof propValue !== 'undefined' ? (propValue as BasicOptionProps).value : propValue;
         const selectedOptions = originalOptions.filter(option => option.value === selectedValue);
 
-        const noMatchOptionInList = !selectedOptions.length && typeof selectedValue !== 'undefined';
+        const noMatchOptionInList = !selectedOptions.length && typeof selectedValue !== 'undefined' && selectedValue !== null;
 
         // If the current value, there is a matching option in the optionList
         if (selectedOptions.length) {

+ 37 - 0
packages/semi-ui/select/_story/select.stories.jsx

@@ -3251,4 +3251,41 @@ export const emptyContent = () => {
   )
 }
 
+export const Fix1584 = () => {
+  return (
+    <>
+      defaultValue is null
+      <br />
+      <Select 
+        style={{ width: 180 }} 
+        defaultValue={null}
+        placeholder="带搜索功能的单选"
+        renderSelectedItem={(item) => {
+          console.log('items', item);  
+          return <div>{item.label}</div>}}
+      >
+        <Select.Option value="abc">抖音</Select.Option>
+        <Select.Option value="ulikecam">轻颜相机</Select.Option>
+        <Select.Option value="jianying">剪映</Select.Option>
+        <Select.Option value="xigua">西瓜视频</Select.Option>
+      </Select>
+      <br />
+      <br />
+      defaultValue is undefined
+      <br />
+      <Select 
+        style={{ width: 180 }} 
+        defaultValue={undefined}
+        placeholder="带搜索功能的单选"
+        renderSelectedItem={(item) => <div>{item.label}</div>}
+      >
+        <Select.Option value="abc">抖音</Select.Option>
+        <Select.Option value="ulikecam">轻颜相机</Select.Option>
+        <Select.Option value="jianying">剪映</Select.Option>
+        <Select.Option value="xigua">西瓜视频</Select.Option>
+      </Select>
+    </>
+  );
+}
+