diff --git a/README.md b/README.md index 71d69aea..4e318b24 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ React Select + [![NPM version][npm-image]][npm-url] [![npm download][download-image]][download-url] [![build status][github-actions-image]][github-actions-url] @@ -67,6 +68,7 @@ export default () => ( ### Select props + | name | description | type | default | | --- | --- | --- | --- | | id | html id to set on the component wrapper | String | '' | @@ -126,6 +128,7 @@ export default () => ( | loading | show loading icon in arrow | boolean | false | | virtual | Disable virtual scroll | boolean | true | | direction | direction of dropdown | 'ltr' \| 'rtl' | 'ltr' | +| optionRender | Custom rendering options | (oriOption: FlattenOptionData\ , info: { index: number }) => React.ReactNode | - | ### Methods diff --git a/docs/demo/option-render.md b/docs/demo/option-render.md new file mode 100644 index 00000000..d203f935 --- /dev/null +++ b/docs/demo/option-render.md @@ -0,0 +1,8 @@ +--- +title: optionRender +nav: + title: Demo + path: /demo +--- + + diff --git a/docs/examples/option-render.tsx b/docs/examples/option-render.tsx new file mode 100644 index 00000000..216fd110 --- /dev/null +++ b/docs/examples/option-render.tsx @@ -0,0 +1,17 @@ +/* eslint-disable no-console */ +import Select from 'rc-select'; +import '../../assets/index.less'; + +export default () => { + return ( + x }} value="1"> + , @@ -277,17 +277,16 @@ describe('Select.Basic', () => { expect(wrapper3.find('.custom-clear-icon').text()).toBe('x'); const wrapper4 = mount( - x }}> , ); expect(wrapper4.find('.custom-clear-icon').length).toBeFalsy(); - resetWarned(); const wrapper5 = mount( - x} value="1"> , @@ -296,7 +295,7 @@ describe('Select.Basic', () => { expect(wrapper5.find('.custom-clear-icon').text()).toBe('x'); const wrapper6 = mount( - x}> , @@ -1361,7 +1360,7 @@ describe('Select.Basic', () => { beforeAll(() => { domHook = spyElementPrototypes(HTMLElement, { getBoundingClientRect: () => ({ - width: 1000 + width: 1000, }), }); }); @@ -2095,4 +2094,24 @@ describe('Select.Basic', () => { const { container } = testingRender( { + return `${option.label} - ${index}`; + }} + />, + ); + expect(container.querySelector('.rc-select-item-option-content').innerHTML).toEqual( + 'test1 - 0', + ); + }); });