Skip to content

Commit

Permalink
feat: select support custom option by option slot
Browse files Browse the repository at this point in the history
  • Loading branch information
tangjinzhou committed Aug 11, 2021
1 parent 07f6d9e commit 68c1f45
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
11 changes: 10 additions & 1 deletion components/select/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,15 @@ const Select = defineComponent({
props: SelectProps(),
SECRET_COMBOBOX_MODE_DO_NOT_USE: 'SECRET_COMBOBOX_MODE_DO_NOT_USE',
emits: ['change', 'update:value'],
slots: ['notFoundContent', 'suffixIcon', 'itemIcon', 'removeIcon', 'clearIcon', 'dropdownRender'],
slots: [
'notFoundContent',
'suffixIcon',
'itemIcon',
'removeIcon',
'clearIcon',
'dropdownRender',
'option',
],
setup(props, { attrs, emit, slots, expose }) {
const selectRef = ref(null);

Expand Down Expand Up @@ -194,6 +202,7 @@ const Select = defineComponent({
dropdownClassName={rcSelectRtlDropDownClassName}
onChange={triggerChange}
dropdownRender={selectProps.dropdownRender || slots.dropdownRender}
v-slots={{ option: slots.option }}
>
{slots.default?.()}
</RcSelect>
Expand Down
10 changes: 7 additions & 3 deletions components/vc-select/OptionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const OptionListProps = {
const OptionList = defineComponent<OptionListProps, { state?: any }>({
name: 'OptionList',
inheritAttrs: false,
slots: ['option'],
setup(props) {
const itemPrefixCls = computed(() => `${props.prefixCls}-item`);

Expand Down Expand Up @@ -268,6 +269,7 @@ const OptionList = defineComponent<OptionListProps, { state?: any }>({
setActive,
onSelectValue,
memoFlattenOptions,
$slots,
} = this as any;
const {
id,
Expand All @@ -281,6 +283,7 @@ const OptionList = defineComponent<OptionListProps, { state?: any }>({
onScroll,
onMouseenter,
} = this.$props as OptionListProps;
const renderOption = $slots.option;
const { activeIndex } = this.state;
// ========================== Render ==========================
if (memoFlattenOptions.length === 0) {
Expand Down Expand Up @@ -315,12 +318,11 @@ const OptionList = defineComponent<OptionListProps, { state?: any }>({
onMouseenter={onMouseenter}
children={({ group, groupOption, data }, itemIndex) => {
const { label, key } = data;

// Group
if (group) {
return (
<div class={classNames(itemPrefixCls, `${itemPrefixCls}-group`)}>
{label !== undefined ? label : key}
{renderOption ? renderOption(data) : label !== undefined ? label : key}
</div>
);
}
Expand Down Expand Up @@ -387,7 +389,9 @@ const OptionList = defineComponent<OptionListProps, { state?: any }>({
}}
style={style}
>
<div class={`${optionPrefixCls}-content`}>{content}</div>
<div class={`${optionPrefixCls}-content`}>
{renderOption ? renderOption(data) : content}
</div>
{isValidElement(menuItemSelectedIcon) || selected}
{iconVisible && (
<TransBtn
Expand Down
1 change: 1 addition & 0 deletions components/vc-select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const Select = defineComponent<Omit<ExportedSelectProps, 'children'>>({
ref={selectRef}
{...(props as any)}
{...attrs}
v-slots={slots}
children={slots.default?.() || []}
/>
);
Expand Down
3 changes: 3 additions & 0 deletions components/vc-select/generate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ export default function generateSelector<
} = config as any;
const Select = defineComponent<SelectProps<OptionsType, ValueType>>({
name: 'Select',
slots: ['option'],
setup(props: SelectProps<OptionsType, ValueType>) {
const useInternalProps = computed(
() => props.internalProps && props.internalProps.mark === INTERNAL_PROPS_MARK,
Expand Down Expand Up @@ -1093,6 +1094,7 @@ export default function generateSelector<
displayValues,
activeValue,
onSearchSubmit,
$slots: slots,
} = this as any;
const {
prefixCls = defaultPrefixCls,
Expand Down Expand Up @@ -1204,6 +1206,7 @@ export default function generateSelector<
menuItemSelectedIcon={menuItemSelectedIcon}
virtual={virtual !== false && dropdownMatchSelectWidth !== false}
onMouseenter={onPopupMouseEnter}
v-slots={{ option: slots.option }}
/>
);

Expand Down
2 changes: 1 addition & 1 deletion v2-doc
Submodule v2-doc updated 65 files
+1 −1 package.json
+6 −5 src/App.vue
+2 −5 src/components/rice/geektime_ads.vue
+2 −4 src/components/rice/right_bottom_rice.vue
+2 −4 src/components/rice/sponsors.vue
+2 −4 src/components/rice/top_rice.vue
+5 −5 src/docs/calendar/demo/basic.vue
+4 −4 src/docs/calendar/demo/card.vue
+16 −15 src/docs/calendar/demo/customize-header.vue
+10 −11 src/docs/calendar/demo/notice-calendar.vue
+29 −8 src/docs/calendar/demo/select.vue
+16 −17 src/docs/calendar/index.en-US.md
+16 −17 src/docs/calendar/index.zh-CN.md
+4 −7 src/docs/comment/demo/basic.vue
+2 −4 src/docs/comment/demo/editor.vue
+7 −10 src/docs/comment/demo/list.vue
+6 −6 src/docs/config-provider/demo/locale.vue
+1 −1 src/docs/config-provider/index.en-US.md
+1 −1 src/docs/config-provider/index.zh-CN.md
+9 −11 src/docs/date-picker/demo/basic.vue
+0 −51 src/docs/date-picker/demo/bordered.vue
+16 −9 src/docs/date-picker/demo/date-render.vue
+13 −18 src/docs/date-picker/demo/disabled-date.vue
+7 −9 src/docs/date-picker/demo/disabled.vue
+2 −2 src/docs/date-picker/demo/extra-footer.vue
+8 −10 src/docs/date-picker/demo/format.vue
+6 −9 src/docs/date-picker/demo/index.vue
+6 −6 src/docs/date-picker/demo/mode.vue
+5 −5 src/docs/date-picker/demo/presetted-ranges.vue
+0 −42 src/docs/date-picker/demo/range-picker.vue
+11 −17 src/docs/date-picker/demo/select-in-range.vue
+5 −3 src/docs/date-picker/demo/size.vue
+5 −5 src/docs/date-picker/demo/start-end.vue
+10 −10 src/docs/date-picker/demo/suffix.vue
+0 −44 src/docs/date-picker/demo/switchable.vue
+6 −5 src/docs/date-picker/demo/text.vue
+4 −4 src/docs/date-picker/demo/time.vue
+77 −84 src/docs/date-picker/index.en-US.md
+77 −91 src/docs/date-picker/index.zh-CN.md
+2 −2 src/docs/form/demo/basic.vue
+2 −2 src/docs/form/demo/validation.vue
+2 −2 src/docs/statistic/index.en-US.md
+2 −2 src/docs/statistic/index.zh-CN.md
+3 −4 src/docs/time-picker/demo/12hours.vue
+4 −6 src/docs/time-picker/demo/addon.vue
+4 −3 src/docs/time-picker/demo/basic.vue
+0 −22 src/docs/time-picker/demo/bordered.vue
+3 −4 src/docs/time-picker/demo/disabled.vue
+3 −4 src/docs/time-picker/demo/hide-column.vue
+0 −6 src/docs/time-picker/demo/index.vue
+0 −21 src/docs/time-picker/demo/range-picker.vue
+4 −4 src/docs/time-picker/demo/size.vue
+4 −4 src/docs/time-picker/demo/suffix.vue
+4 −4 src/docs/time-picker/demo/value.vue
+27 −39 src/docs/time-picker/index.en-US.md
+16 −30 src/docs/time-picker/index.zh-CN.md
+3 −3 src/layouts/Footer.vue
+0 −10 src/router/index.js
+2 −2 src/views/jobs.vue
+6 −2 src/vueDocs/faq.en-US.md
+9 −1 src/vueDocs/faq.zh-CN.md
+1 −1 src/vueDocs/introduce.en-US.md
+1 −1 src/vueDocs/introduce.zh-CN.md
+0 −27 src/vueDocs/replace-date.en-US.md
+0 −27 src/vueDocs/replace-date.zh-CN.md

0 comments on commit 68c1f45

Please sign in to comment.