Skip to content

Commit

Permalink
feat: 优化 Select 的 placeholder 实现
Browse files Browse the repository at this point in the history
  • Loading branch information
limaofeng committed Jul 13, 2022
1 parent 36c0218 commit ae19f97
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/properties/data-entry/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
SelectProps,
} from '../typings';

function defaultRenderTitle(value?: SelectOption, placeholder?: string) {
return value?.label || placeholder;
function defaultRenderTitle(value?: SelectOption) {
return value?.label;
}

function defaultCompare(value: string, option: SelectOption) {
Expand Down Expand Up @@ -110,7 +110,7 @@ const Select = (props: SelectProps) => {
placeholder = '请选择',
popover: SelectPopover = SelectModal,
popoverClassName,
dropdownMatchSelectWidth,
dropdownMatchSelectWidth = true,
className,
} = props;
const ref = useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -192,7 +192,9 @@ const Select = (props: SelectProps) => {
onClick={handleClick}
>
{icon && renderIcon(icon)}
<div className="select-title">{renderTitle(getOption(options, value!), placeholder)}</div>
<div className="select-title" placeholder={placeholder}>
{renderTitle(getOption(options, value!))}
</div>
<div className="indicator">
<Icon name="AsanyEditor/DownArrow" />
</div>
Expand Down
6 changes: 6 additions & 0 deletions src/style/design.less
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,12 @@
height: 28px;
}

.select-title[placeholder]:empty:before {
color: #bfbfbf;
background-color: transparent;
content: attr(placeholder);
}

&:not(:disabled):hover {
border: 1px solid var(--selected-background-color);
border-radius: 2px;
Expand Down

0 comments on commit ae19f97

Please sign in to comment.