Skip to content

Commit

Permalink
fix: When all items except the disabled item in the left panel of tra… (
Browse files Browse the repository at this point in the history
#2574)

* fix: When all items except the disabled item in the left panel of transfer are selected, the operation button should display Cancel all selections

* chore: Fix variable typo
  • Loading branch information
YyumeiZhang authored Nov 18, 2024
1 parent c9d5dba commit cde4825
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/semi-foundation/transfer/transfer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ $module: #{$prefix}-transfer;
margin-bottom: $spacing-transfer_header-marginBottom;
margin-left: $spacing-transfer_header-marginLeft;
color: $color-transfer_header-text;
flex-shrink: 0;

&-all {
font-weight: $font-transfer_header_all-fontWeight;
Expand Down
27 changes: 19 additions & 8 deletions packages/semi-ui/transfer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -409,18 +409,28 @@ class Transfer extends BaseComponent<TransferProps, TransferState> {
// For example, the filtered data on the left is 1, 3, 4;
// The selected option is 1,2,3,4, it is true
// The selected option is 2,3,4, then it is false
const leftContainesNotInSelected = Boolean(filterData.find(f => !selectedItems.has(f.key)));
let filterDataAllDisabled = true;
const leftContainsNotInSelected = Boolean(filterData.find(f => {
if (f.disabled) {
return false;
} else {
if (filterDataAllDisabled) {
filterDataAllDisabled = false;
}
return !selectedItems.has(f.key);
}
}));

const totalText = totalToken.replace('${total}', `${showNumber}`);

const headerConfig: HeaderConfig = {
totalContent: totalText,
allContent: leftContainesNotInSelected ? locale.selectAll : locale.clearSelectAll,
onAllClick: () => this.foundation.handleAll(leftContainesNotInSelected),
allContent: leftContainsNotInSelected ? locale.selectAll : locale.clearSelectAll,
onAllClick: () => this.foundation.handleAll(leftContainsNotInSelected),
type: 'left',
showButton: type !== strings.TYPE_TREE_TO_LIST,
showButton: type !== strings.TYPE_TREE_TO_LIST && !filterDataAllDisabled,
num: showNumber,
allChecked: !leftContainesNotInSelected
allChecked: !leftContainsNotInSelected
};
const inputCom = this.renderFilter(locale);
const headerCom = this.renderHeader(headerConfig);
Expand Down Expand Up @@ -472,13 +482,13 @@ class Transfer extends BaseComponent<TransferProps, TransferState> {
filterData,
sourceData: data,
propsDataSource: dataSource,
allChecked: !leftContainesNotInSelected,
allChecked: !leftContainsNotInSelected,
showNumber,
inputValue,
selectedItems,
value: values,
onSelect: this.foundation.handleSelect.bind(this.foundation),
onAllClick: () => this.foundation.handleAll(leftContainesNotInSelected),
onAllClick: () => this.foundation.handleAll(leftContainsNotInSelected),
onSearch: this.onInputChange,
onSelectOrRemove: (item: ResolvedDataItem) => this.onSelectOrRemove(item),
};
Expand Down Expand Up @@ -638,12 +648,13 @@ class Transfer extends BaseComponent<TransferProps, TransferState> {
}
const selectedToken = locale.selected;
const selectedText = selectedToken.replace('${total}', `${selectedData.length}`);
const hasValidSelected = selectedData.findIndex(item => !item.disabled) !== -1;
const headerConfig = {
totalContent: selectedText,
allContent: locale.clear,
onAllClick: () => this.foundation.handleClear(),
type: 'right',
showButton: Boolean(selectedData.length),
showButton: Boolean(selectedData.length) && hasValidSelected,
num: selectedData.length,
};
const headerCom = this.renderHeader(headerConfig);
Expand Down

0 comments on commit cde4825

Please sign in to comment.