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

Feature/select add section classes #3159

Merged
merged 3 commits into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions components/select/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,23 @@ function getListItems(props, state, rawFilterString, data = props.data) {
(add && filterString && !exactMatch) ||
(add && add.alwaysVisible)
) {
if (!(add.regexp && !add.regexp.test(filterString)) &&
if (
!(add.regexp && !add.regexp.test(filterString)) &&
!(add.minlength && filterString.length < +add.minlength) ||
add.alwaysVisible) {
add.alwaysVisible
) {
let label;

if (add.label) {
label = (typeof add.label === 'function') ? add.label(filterString) : add.label;

} else {
label = filterString;
}

addButton = {
prefix: add.prefix,
label: add.label || filterString,
label,
delayed: add.hasOwnProperty('delayed') ? add.delayed : true
};
}
Expand Down
14 changes: 14 additions & 0 deletions components/select/select.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,20 @@ describe('Select', () => {
addButton.should.contain.text('Add Something');
});

it('Should process filterValue into a label at the "Add" button if "add.label" prop is a function', () => {
const wrapper = mountSelect({
add: {
label: value => `--${value}--`
}
});
const instance = wrapper.instance();
instance.filterValue = sandbox.stub().returns('test');
instance._showPopup();
const addButton = instance._popup.popup.popup.querySelector(`.${styles.button}`);

addButton.should.contain.text('--test--');
});

it('Should add hint if specified', () => {
const wrapper = mountSelect({
hint: 'blah blah'
Expand Down
Loading