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

feat(OnyxStepper): implement strip step and precision #1976

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

ChristianBusshoff
Copy link
Contributor

  • added strip step Mode (values that do not fit the step size, a stepMismatch error is shown)
  • added precision (always display the given number of decimals places)
  • applied the spin button aria pattern

@ChristianBusshoff ChristianBusshoff requested a review from a team as a code owner October 18, 2024 08:46
Copy link

changeset-bot bot commented Oct 18, 2024

⚠️ No Changeset found

Latest commit: b55b677

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

}
};
const handleChange = () => {
if (inputRef.value) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Avoding intendation is preferable, to keep readability high

Suggested change
if (inputRef.value) {
if (!inputRef.value) return;

/**
* Current value (with getter and setter) that can be used as "v-model" for the native input.
*/
const value = computed({
get: () => props.modelValue,
set: (value) => emit("update:modelValue", value),
});
const displayValue = ref<number | string | undefined>();

const updateValue = (newValue: number) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

IMHO we should switch to more reactive approach.
I would propose this simplified approach:

  • emitting the parsed number on @change
  • displayValue should only be write-bound and be computed based on props.modelValue

Comment on lines 37 to +47
*/
step?: number;
/**
* Ensures that the value is a multiple of the step size.
*/
stripStep?: boolean;
/**
* Defines the number of decimal places to display.
*/
precision?: number;

Copy link
Collaborator

Choose a reason for hiding this comment

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

As discussed:

    /**
     * Incremental step.
     * @deprecated
     */
    step?: number; // step-mismatch + step-increment


    /**
     * The smallest allowed value and rounded precision
     */
    precision?: number; // step-mismatch => uses :step="props.precision" for the validation
    /**
     * The increment number
     * @default precision is the default stepSize
     */
    stepSize?: number; //  step-increment => number which is used for increment/decrement

Comment on lines +140 to 141
@change="handleChange"
/>
Copy link
Collaborator

Choose a reason for hiding this comment

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

@keydown.up.prevent="handleClick('stepUp')"
@keydown.down.prevent="handleClick('stepDown')"

@@ -91,7 +121,7 @@ const decrementLabel = computed(() => t.value("stepper.decrement", { stepSize: p
<input
v-else
ref="inputRef"
v-model.number="value"
v-model.number="displayValue"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
v-model.number="displayValue"
:value="displayValue"

@JoCa96 JoCa96 self-assigned this Oct 22, 2024
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