Skip to content

Commit

Permalink
* picker: refactor and fix undefined error.
Browse files Browse the repository at this point in the history
  • Loading branch information
catouse committed Mar 22, 2024
1 parent d823994 commit 0497edd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
14 changes: 11 additions & 3 deletions lib/picker/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,17 @@ onPageUpdate(() => {
console.log('> multiPicker', multiPicker);

const noSearchPicker = new Picker('#noSearchPicker', {
items,
search: false,
display: '已选择 {text}',
'multiple': true,
'items': [
{'text': '查看研发需求', 'value': 'story', 'items': [{'text': 'SR1', 'value': '1'}, {'text': 'SR2', 'value': '2'}, {'text': 'SR3', 'value': '3'}, {'text': 'SR4', 'value': '4'}]},
],
'search': false,
'display': 'test {value}',
'emptyValue': '',
'defaultValue': '',
menu: {
checkbox: true,
},
});
console.log('> noSearchPicker', noSearchPicker);

Expand Down
6 changes: 3 additions & 3 deletions lib/picker/src/component/picker-single-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ export class PickerSingleSelect extends PickTrigger<PickerState, PickerSelectPro
protected _renderTrigger(props: PickerSelectProps) {
const {children, state: {selections = [], value, open}, placeholder, search, disabled, readonly, clearable, display} = props;

const [selection] = selections;
const [selection = {text: '', value: ''}] = selections;
const showSearch = open && search;
let view: ComponentChildren;
if (showSearch) {
view = this._renderSearch(props);
} else if (selection || (placeholder === undefined && display)) {
const {text} = selection;
const {text = ''} = selection;
if (typeof display === 'function') {
view = display.call(this, value, selection);
view = display.call(this, value, selections);
} else if (typeof display === 'string') {
view = formatString(display, selection);
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/picker/src/types/picker-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface PickerOptions<S extends PickerState = PickerState> extends Pick
cache?: boolean;
searchDelay?: number;
searchEmptyHint?: string;
display?: string | ((values: string | string[], selections: PickerItemBasic | PickerItemBasic[]) => CustomContentType);
display?: string | ((values: string | string[], selections: PickerItemBasic[]) => CustomContentType);
search?: boolean | number;
searchHint?: string;
hotkeys?: HotkeysSettings;
Expand Down
2 changes: 1 addition & 1 deletion lib/picker/src/types/picker-select-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface PickerSelectProps<S extends PickerState = PickerState> extends
valueList: string[];
emptyValue: string;
hotkeys?: HotkeysSettings;
display?: string | ((values: string | string[], selections: PickerItemBasic | PickerItemBasic[]) => CustomContentType);
display?: string | ((values: string | string[], selections: PickerItemBasic[]) => CustomContentType);

onSelect: (values: string | string[]) => void;
onDeselect: (values: string | string[]) => void;
Expand Down

0 comments on commit 0497edd

Please sign in to comment.