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

fix: remove unnecessary _showOverlayCondition #2453

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

maxevilmind
Copy link
Contributor

@maxevilmind maxevilmind commented Jan 21, 2025

Found a behavior that seems unintended. As far as I can say from code comments and overall familiarity with logic, _showOnverlayCondition is intended to be called only on keyUp. Looks like calling it in a _textboxOnInput is unnecessary and it will cause some weird edge-cases when subclassers override _showOnverlayCondition. This is due to difference in how _showOnverlayCondition is parametrized when called on keyUp (with an ev keyboard event) and in _textboxOnInput (with {}).

Scenario which breaks without the proposed change:
A subclasser wants to implement a functionatily when overlay will only show if input length is >= 3.
They would override a method like this:

_showOverlayCondition(options) {
    const hideOnKeys = ['Tab', 'Escape', 'Enter'];
    if (this.minSearchChars && !hideOnKeys.includes(options.lastKey)) {
      return options.currentValue?.length >= this.minSearchChars;
    } else {
      return super._showOverlayCondition(options);
    }
  }

In runtime _showOverlayCondition method would be called twice, seemingly on keyDown and keyUp but upon closer look, first call comes from _textboxOnInput.
As _showOverlayCondition first call will come from _textboxOnInput, options will equal { } and it will close overlay and set input value of textbox to ''.

It looks logical to me to get rid of this line. Tests pass.

Copy link

changeset-bot bot commented Jan 21, 2025

⚠️ No Changeset found

Latest commit: acae80c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@okadurin
Copy link
Collaborator

Hi @maxevilmind, thank you for the contribution! Could you add a test that fails with the current setup?

@maxevilmind
Copy link
Contributor Author

Hi @okadurin !
Yeah, I will add a test when I have a spare moment.

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

Successfully merging this pull request may close these issues.

2 participants