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

🚀 - Delete calibration on initialization + create maskitoInitialCalibrationPlugin #604

Closed
nsbarsukov opened this issue Oct 18, 2023 · 3 comments · Fixed by #778
Closed
Assignees
Labels
2.x.x Candidate for 2.0.0 release feature New feature or request scope: core Related to @maskito/core

Comments

@nsbarsukov
Copy link
Member

nsbarsukov commented Oct 18, 2023

Which package(s) are relevant/related to the feature request?

@maskito/core

Description

Delete this line

this.ensureValueFitsMask();

+ add maskitoInitialCalibrationPlugin (inside @maskito/core or @maskito/kit ???):

export function maskitoInitialCalibrationPlugin(
    customOptions?: MaskitoOptions,
): MaskitoPlugin {
    return (element, options) => {
        element.value = maskitoTransform(element.value, customOptions || options);
    };
}

Why?

The current implementation is not so flexible as required.
Sometimes the such initial calibration is not required for developer, and develop wants calibration to work only on user's interactions.

The new way allows to select: use maskitoInitialCalibrationPlugin or not.

@nsbarsukov nsbarsukov added feature New feature or request 2.x.x Candidate for 2.0.0 release labels Oct 18, 2023
@github-project-automation github-project-automation bot moved this to 💡 Backlog in Taiga-family Oct 18, 2023
@nsbarsukov
Copy link
Member Author

For these cases

describe('runtime changes of postfix', () => {
beforeEach(() => {
cy.visit(DemoPath.Cypress);
cy.get('#runtime-postfix-changes input')
.focus()
.should('have.value', '1 year')
.as('input');
});
it('1| year => Type 0 => 10| years', () => {
cy.get('@input')
.type('{moveToStart}{rightArrow}')
.type('0')
.should('have.value', '10 years')
.should('have.prop', 'selectionStart', '10'.length)
.should('have.prop', 'selectionEnd', '10'.length);
});
it('10| years => Backspace => 1| year', () => {
cy.get('@input')
.type('{moveToStart}{rightArrow}')
.type('0')
.should('have.value', '10 years')
.type('{backspace}')
.should('have.value', '1 year')
.should('have.prop', 'selectionStart', '1'.length)
.should('have.prop', 'selectionEnd', '1'.length);
});

Developer can use the optional argument of maskitoInitialCalibrationPlugin.

input-number.component.ts:

@tuiPure
private calculateMask(
    precision: number,
    decimalMode: TuiDecimal,
    decimalSeparator: string,
    thousandSeparator: string,
    min: number,
    max: number,
    prefix: string,
    postfix: string,
): MaskitoOptions {
    const generatorParams = {
        decimalSeparator,
        thousandSeparator,
        min,
        max,
        prefix,
        postfix,
        precision: decimalMode === 'never' ? 0 : precision,
        decimalZeroPadding: decimalMode === 'always',
    };
    const {plugins, ...options} = maskitoNumberOptionsGenerator(generatorParams);
    const initialCalibrationPlugin = maskitoInitialCalibrationPlugin(
        maskitoNumberOptionsGenerator({
                ...generatorParams,
                min: Number.MIN_SAFE_INTEGER,
                max: Number.MAX_SAFE_INTEGER
        })
    );

    return {
        ...options,
        plugins: [
            ...plugins,
            initialCalibrationPlugin,
            maskitoCaretGuard(value => [
                prefix.length,
                value.length - postfix.length,
            ]),
        ],
    };
}

@nsbarsukov

This comment was marked as off-topic.

@nsbarsukov

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.x.x Candidate for 2.0.0 release feature New feature or request scope: core Related to @maskito/core
Projects
No open projects
Status: Done
1 participant