Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions code/addons/docs/src/blocks/controls/Number.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,31 @@ export const NumberControl: FC<NumberProps> = ({
if (Number.isNaN(result)) {
setParseError(new Error(`'${event.target.value}' is not a number`));
} else {
onChange(result);
// Initialize the final value as the user's input
let finalValue = result;

// Clamp to minimum: if finalValue is less than min, use min
if (typeof min === 'number' && finalValue < min) {
finalValue = min;
}

// Clamp to maximum: if finalValue is greater than max, use max
if (typeof max === 'number' && finalValue > max) {
finalValue = max;
}

// Pass the clamped final value to the onChange callback
onChange(finalValue);
// Clear any previous parse errors
setParseError(null);

// If the value was clamped, update the input display to the final value
if (finalValue !== result) {
setInputValue(String(finalValue));
}
}
},
[onChange, setParseError]
[onChange, setParseError, min, max]
);

const onForceVisible = useCallback(() => {
Expand Down
2 changes: 1 addition & 1 deletion code/frameworks/sveltekit/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"baseUrl": ".",
"paths": {
"storybook/internal/*": ["../../lib/cli/core/*"]
},
}
},
"extends": "../../tsconfig.json",
"include": ["src/**/*"]
Expand Down
1 change: 0 additions & 1 deletion code/lib/eslint-plugin/docs/rules/no-stories-of.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Examples of **incorrect** code for this rule:

```js
import { storiesOf } from '@storybook/react';

import Button from '../components/Button';

storiesOf('Button', module).add('primary', () => <Button primary />);
Expand Down