Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions assets/patch.less
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@
margin-right: 4px;
}

.@{select-prefix}-placeholder {
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
}

.@{select-prefix}-input {
width: calc(var(--select-input-width, 10) * 1px);
min-width: 4px;
Expand Down
1 change: 0 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module.exports = {
setupFilesAfterEnv: ['<rootDir>/tests/setup.ts'],
collectCoverage: true,
collectCoverageFrom: ['src/**/*.{ts,tsx,js,jsx}'],
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"@rc-component/trigger": "^3.0.0",
"@rc-component/util": "^1.3.0",
"clsx": "^2.1.1",
"rc-overflow": "^1.4.0",
"rc-overflow": "^1.5.0",
"rc-virtual-list": "^3.5.2"
},
"devDependencies": {
Expand Down
41 changes: 19 additions & 22 deletions src/SelectInput/Content/MultipleContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,27 +183,24 @@ export default React.forwardRef<HTMLInputElement, SharedContentProps>(function M

// ======================= Render =======================
return (
<>
<Placeholder show={!searchValue || !triggerOpen} />
<Overflow
prefixCls={`${prefixCls}-content`}
data={displayValues}
renderItem={renderItem}
renderRest={renderRest}
// suffix={inputNode}
suffix={
<Input
ref={ref}
disabled={disabled}
readOnly={!inputEditable}
{...inputProps}
value={inputValue || ''}
syncWidth
/>
}
itemKey={itemKey}
maxCount={maxTagCount}
/>
</>
<Overflow
prefixCls={`${prefixCls}-content`}
prefix={!displayValues.length && (!searchValue || !triggerOpen) ? <Placeholder /> : null}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The condition to render the Placeholder includes !displayValues.length. However, the Placeholder component itself already contains logic to return null if displayValues is not empty. This creates redundant logic and couples the components unnecessarily.

To improve separation of concerns, you can remove the !displayValues.length check from here and let the Placeholder component be solely responsible for determining its visibility based on displayValues.

Suggested change
prefix={!displayValues.length && (!searchValue || !triggerOpen) ? <Placeholder /> : null}
prefix={(!searchValue || !triggerOpen) ? <Placeholder /> : null}

data={displayValues}
renderItem={renderItem}
renderRest={renderRest}
suffix={
<Input
ref={ref}
disabled={disabled}
readOnly={!inputEditable}
{...inputProps}
value={inputValue || ''}
syncWidth
/>
}
itemKey={itemKey}
maxCount={maxTagCount}
/>
);
});
4 changes: 2 additions & 2 deletions src/SelectInput/Content/Placeholder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import * as React from 'react';
import { useSelectInputContext } from '../context';

export interface PlaceholderProps {
show: boolean;
show?: boolean;
}

export default function Placeholder(props: PlaceholderProps) {
const { prefixCls, placeholder, displayValues } = useSelectInputContext();
const { show } = props;
const { show = true } = props;

if (displayValues.length) {
return null;
Expand Down
4 changes: 1 addition & 3 deletions tests/Multiple.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,7 @@ describe('Select.Multiple', () => {
visibility: 'visible',
});
toggleOpen(container);
expect(container.querySelector('.rc-select-placeholder')).toHaveStyle({
visibility: 'hidden',
});
expect(container.querySelector('.rc-select-placeholder')).toBeFalsy();
});

it('clear input when popup closed', () => {
Expand Down
Loading