Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Antd] Select can not work with mode='tags' #2

Closed
nvlong198 opened this issue Nov 12, 2020 · 7 comments
Closed

[Antd] Select can not work with mode='tags' #2

nvlong198 opened this issue Nov 12, 2020 · 7 comments
Assignees

Comments

@nvlong198
Copy link

Select can not work with mode='tags', become mode='multiple' when using with react-js-cron

playground: https://stackblitz.com/edit/react-mdwfya?file=index.js

@nvlong198 nvlong198 changed the title [Antd] Select can not work with mode='tags', become mode='multiple' when using with react-js-cron [Antd] Select can not work with mode='tags' Nov 12, 2020
@nvlong198
Copy link
Author

nvlong198 commented Nov 12, 2020

@xrutayisire I found the problem is in components/CustomSelect

what actually element.setAttribute('readonly', 'readonly') do ?

useEffect(() => {
    Array.from(
      document.getElementsByClassName('ant-select-selection-search-input')
    ).forEach((element: Element) => {
      element.setAttribute('readonly', 'readonly')
    })
  }, [])

@xrutayisire
Copy link
Owner

Hey,

Thanks for the report!

I see the problem, I will provide a fix 👍

useEffect(() => {
    Array.from(
      document.getElementsByClassName('ant-select-selection-search-input')
    ).forEach((element: Element) => {
      element.setAttribute('readonly', 'readonly')
    })
  }, [])

This code is used to disabled hidden search input of antd that cause problems because we don't want any search field on it.

@xrutayisire xrutayisire self-assigned this Nov 12, 2020
@nvlong198
Copy link
Author

nvlong198 commented Nov 12, 2020

Any problems if change mode to 'multiple' and remove that useEffect ?

<Select
      mode='multiple'
      allowClear={!readOnly}
.... />

@xrutayisire
Copy link
Owner

xrutayisire commented Nov 12, 2020

As you can see on the following screenshot, it's not wanted to let the user type anything in the search input:

Screenshot 2020-11-12 at 13 50 21

And Design provide a "showSearch" property but it's not working with the "tags" mode 😕

@xrutayisire
Copy link
Owner

I heavily use the prop "tagRender" from antd so that's why I used "tags" mode.

I just checked antd documentation and then RcSelect documentation about "tagRender" and they added unit tests and examples only with "tags" mode.

BUT the doc don't talk about the "mode" (yet)

tagRender | Customize tag render | (props) => ReactNode

BUT again, it's currently working with "multiple" as you point out...
In their code they don't test the mode https://github.com/react-component/select/blob/05d19a953315f4ecd5510dbc6d4bd5230ccff6e5/src/Selector/MultipleSelector.tsx#L145 .

Let me check If I find out mode about the use of "tagRender" with "multiple" 🙂

If you have any indication I'm open for it!

@xrutayisire
Copy link
Owner

xrutayisire commented Nov 12, 2020

Ok, it seems to be ok to use it with "multiple". 🥳
For me, they should have named it differently because of the explicit mode "tags".

Anyway to give you info about it:

And as you can see here (ant-design/ant-design#21064 (comment)) they even discussed it with "multiple" mode and updated the demo: https://github.com/ant-design/ant-design/blob/master/components/select/demo/custom-tag-render.md#en-us

So good for me, let me change that, check if everything work fine and I will release a new hotfix of "react-js-cron".

@xrutayisire
Copy link
Owner

It's live 🥳

New version 1.1.1: https://www.npmjs.com/package/react-js-cron

Try it and let me know but you should not have any problem now 🙂

I forked your example to show you the fix: https://stackblitz.com/edit/react-mdwfya-t1i1wg?file=package.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants