Uh oh!
There was an error while loading. Please reload this page.
Restore Standard Select Controls - #974
Open
ZachAlanMueller wants to merge 1 commit into
Open
Conversation
Selects standard controls allow for arrow keys up/down to select the previous/next option, and then when a user tabs, it keeps that selected option. This commit restores that lost functionality. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select#technical_summary
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
yoyo837
commented
Aug 14, 2023
Member
Please add some test case for it. |
ZachAlanMueller
commented
Aug 14, 2023
Author
Thank you for your feedback. I understand that you would like me to add some test cases for the new feature. I apologize for not knowing how to do this, as I am still new to unit testing. I would like to learn how to add test cases, so that I can be more helpful in the future. Would you be able to provide me with some resources or training on unit testing? |
sixwinds
commented
Sep 4, 2023
I have a temp fall back implementation, the idea is that find the active option dom node when blur: // libsimport{useRef}from'react';import{Select}from'antd';// utilsimportisFunctionfrom'@/utils/isFunction';// this func is based on antd version 4, you can customized it on your antd versionconstgetActiveOpitonContentElement=(rootElement)=>{if(rootElement){constactiveOptionElement=rootElement.getElementsByClassName('ant-select-item-option-active',)?.[0];if(activeOptionElement){constoptionContentElement=activeOptionElement.getElementsByClassName('ant-select-item-option-content',)?.[0];returnoptionContentElement;}}returnvoid0;};constMySelect=(props)=>{const{
options,
optionFilterProp,
dropdownRender,
onBlur,
onChange,
...restProps}=props;constdropdownWrapperElementRef=useRef();return(<Select{...restProps}onChange={onChange}optionFilterProp={optionFilterProp}options={options}dropdownRender={(originNode)=>{if(isFunction(dropdownRender)){return(<divref={dropdownWrapperElementRef}>{dropdownRender(originNode)}</div>)}return(<divref={dropdownWrapperElementRef}>{originNode}</div>);}}onBlur={(...args)=>{// ---- [implementation of tabbing to select active option] start -----constactiveOptionContentElement=getActiveOpitonContentElement(dropdownWrapperElementRef.current,);if(activeOptionContentElement&&Array.isArray(options)&&options.length>0){constactiveOption=options.find((el)=>{return(el[optionFilterProp??'value']===activeOptionContentElement.innerText);});if(activeOption&&isFunction(onChange)){onChange(activeOption.value);}}// ---- [implementation of tabbing to select active option] end -----if(isFunction(onBlur)){onBlur(...args);}}}/>);};It is based on antd version 4, but I think developer can customized the implementation. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Vanilla HTML Selects standard controls allow for arrow keys up/down to select the previous/next option, and then when a user tabs, it keeps that selected option. This commit implements that functionality into rc-select.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select#technical_summary
This functionality has been asked for by the community for Ant Design over the years, see issue here:
closeant-design/ant-design#26876
Please forgive me if I've done this PR incorrectly, I'm unfamiliar with the procedure, and if I did anything wrong, please let me know so that I can do better next time.