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(input): fix set selection range #1488

Merged
merged 2 commits into from
Dec 13, 2024
Merged

Conversation

reabiliti
Copy link
Contributor

Опишите проблему

При поднятии версии пакета начали падать тесты с ошибкой InvalidStateError

https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setSelectionRange

метод поддерживается только на определенных типах инпута

Copy link

changeset-bot bot commented Dec 10, 2024

🦋 Changeset detected

Latest commit: 8e8e189

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 25 packages
Name Type
@alfalab/core-components-input Patch
@alfalab/core-components-amount-input Patch
@alfalab/core-components-date-input Patch
@alfalab/core-components-date-range-input Patch
@alfalab/core-components-date-time-input Patch
@alfalab/core-components-input-autocomplete Patch
@alfalab/core-components-international-phone-input Patch
@alfalab/core-components-masked-input Patch
@alfalab/core-components-number-input Patch
@alfalab/core-components-password-input Patch
@alfalab/core-components-select Patch
@alfalab/core-components-slider-input Patch
@alfalab/core-components-time-input Patch
@alfalab/core-components-universal-date-input Patch
@alfalab/core-components-with-suffix Patch
@alfalab/core-components-calendar-input Patch
@alfalab/core-components-calendar-range Patch
@alfalab/core-components-intl-phone-input Patch
@alfalab/core-components-bank-card Patch
@alfalab/core-components-phone-input Patch
@alfalab/core-components-custom-picker-button Patch
@alfalab/core-components-picker-button Patch
@alfalab/core-components-select-with-tags Patch
@alfalab/core-components-table Patch
@alfalab/core-components-tabs Patch

Not sure what this means? Click here to learn what changesets are.

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

@coveralls
Copy link

coveralls commented Dec 10, 2024

Pull Request Test Coverage Report for Build 12278796593

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 3 of 4 (75.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.004%) to 82.306%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/input/src/components/base-input/Component.tsx 3 4 75.0%
Totals Coverage Status
Change from base Build 12256710958: 0.004%
Covered Lines: 10633
Relevant Lines: 11792

💛 - Coveralls

@core-ds-bot
Copy link
Collaborator

Собрана новая демка.

@@ -288,7 +290,7 @@ export const BaseInput = React.forwardRef<HTMLInputElement, BaseInputProps>(
if (restProps.autoFocus) {
const input = inputRef.current;

if (input) {
if (input && inputTypesForSelectionRange.includes(input.type)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

        useLayoutEffect_SAFE_FOR_SSR(() => {
            const input = inputRef.current;

            if (
                !restProps.autoFocus ||
                !input ||
                // https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setSelectionRange
                !inputTypesForSelectionRange.includes(input.type)
            ) {
                return;
            }

            // https://github.com/facebook/react/issues/14125
            input.setSelectionRange(input.value.length, input.value.length);
        }, []);

может поправим сразу?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

спасибо ) подправил

@core-ds-bot
Copy link
Collaborator

Собрана новая демка.

@fulcanellee fulcanellee merged commit 8987193 into master Dec 13, 2024
7 checks passed
@fulcanellee fulcanellee deleted the fix/input-selection-range branch December 13, 2024 09:48
NikitaRodyukov pushed a commit that referenced this pull request Dec 25, 2024
* fix(input): fix set selection range

* feat(input): refactor use effect

---------

Co-authored-by: Aleksandr Dyuzhikov <adyuzhikov@alfabank.ru>
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.

6 participants