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

Resolved issue #4511 to reposition open dropdown when a selection is made #4601

Closed
wants to merge 2 commits into from
Closed

Resolved issue #4511 to reposition open dropdown when a selection is made #4601

wants to merge 2 commits into from

Conversation

devmonkey22
Copy link
Contributor

This pull request includes a

  • Bug fix
  • New feature
  • Translation

The following changes were made:

  • In AttachBody bind method, added handler to watch select and unselect events from container. This allows the dropdown to reposition if the underlying selection object changes positions because it wraps onto another line, or if options are unselected, makes sure it snaps back up below selection object (so it doesn't float).

If this is related to an existing ticket, include a link to it as well.
#4511

Copy link
Member

@kevin-brown kevin-brown left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left a few in-line comments about things which you may want to look into before we can accept this pull request into Select2.

Additionally, it would be helpful if we could get a test case that verifies that this issue has been fixed, so we don't need to worry about it breaking in the future. The test case should fail before this commit is applied, and pass afterwards. You can find some existing positioning tests in the repository to give you a start.

If you can't get a working test case, that's not as much of an issue, it's just something we prefer.

@@ -32,6 +32,15 @@ define([
self._resizeDropdown();
});
}

function repositionOnSelectionChange() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tabbing appears to be off here, as it looks like you are using a combination of spaces and tabs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes - apologies. It looks like your convention is a space indented file, so I'll modify.

@@ -32,6 +32,15 @@ define([
self._resizeDropdown();
});
}

function repositionOnSelectionChange() {
if (!this.options.get('closeOnSelect')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the reasoning behind the special case here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may only want to reposition the dropdown if you can detect that the dropdown is still open. I think that may have been what you were going for here, but you can probably solve the issue by looking at the dropdown state instead of checking for a specific option.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was originally trying to only reposition if I knew the dropdown wasn't about to be closed due to the closeOnSelect option. I had originally incorrectly assumed the container.isOpen might have given me the wrong value depending on the order of the decorator chain, however, it does look like this check works more generically. I'll modify and commit.

@devmonkey22
Copy link
Contributor Author

@kevin-brown Thanks for the quick review of this PR. I looked over the positioning-tests.js - it would take me a while to digest it all and write an appropriate unit test.

It looks like I would need to try to combine the approaches in positioning-tests and possibly selectOnClose-tests.js to render the dropdown with a small width, set closeOnSelect to false, add multiple options to cause the selection element to wrap and re-check the position of the dropdown?

I know the value of making sure the tests are in place. I don't know that I can post a test quickly. I hate to ask, but would you be able to help write one for this change?

Thanks,
Mike

@devmonkey22 devmonkey22 changed the title Resolved https://github.com/select2/select2/issues/4511 Resolved issue #4511 to reposition open dropdown when a selection is made Sep 26, 2016
@subssn21
Copy link

Can we please get this Pull Request Merged. This was causing a huge problem with our application when we upgraded from 3.x to 4.x, I had to apply this patch to a local copy of select2, but it worked beautifully and solved the problem.

@stale
Copy link

stale bot commented Mar 13, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale
Copy link

stale bot commented May 18, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the status: stale label May 18, 2019
@stale stale bot closed this May 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants