-
-
Notifications
You must be signed in to change notification settings - Fork 185
feat(spinner): support spinner type #721
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
Changes from 6 commits
d6cec40
1db7175
71c4bc6
6b2bdec
dfd8e1b
9ec02df
150bd00
8f5de3f
a38ca89
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /* eslint no-console:0 */ | ||
| import InputNumber from '@rc-component/input-number'; | ||
| import React from 'react'; | ||
| import '../../assets/index.less'; | ||
|
|
||
| export default () => { | ||
| const [disabled, setDisabled] = React.useState(false); | ||
| const [readOnly, setReadOnly] = React.useState(false); | ||
| const [keyboard, setKeyboard] = React.useState(true); | ||
| const [wheel, setWheel] = React.useState(true); | ||
| const [stringMode, setStringMode] = React.useState(false); | ||
| const [value, setValue] = React.useState<string | number>(93); | ||
|
|
||
| const onChange = (val: number) => { | ||
guoyunhe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| console.warn('onChange:', val, typeof val); | ||
| setValue(val); | ||
| }; | ||
|
|
||
| return ( | ||
| <div style={{ margin: 10 }}> | ||
| <h3>Controlled</h3> | ||
| <InputNumber | ||
| type="spinner" | ||
| aria-label="Simple number input example" | ||
| min={-8} | ||
| max={10} | ||
| style={{ width: 100 }} | ||
| value={value} | ||
| onChange={onChange} | ||
| readOnly={readOnly} | ||
| disabled={disabled} | ||
| keyboard={keyboard} | ||
| changeOnWheel={wheel} | ||
| stringMode={stringMode} | ||
| /> | ||
| <p> | ||
| <button type="button" onClick={() => setDisabled(!disabled)}> | ||
| toggle Disabled ({String(disabled)}) | ||
| </button> | ||
| <button type="button" onClick={() => setReadOnly(!readOnly)}> | ||
| toggle readOnly ({String(readOnly)}) | ||
| </button> | ||
| <button type="button" onClick={() => setKeyboard(!keyboard)}> | ||
| toggle keyboard ({String(keyboard)}) | ||
| </button> | ||
| <button type="button" onClick={() => setStringMode(!stringMode)}> | ||
| toggle stringMode ({String(stringMode)}) | ||
| </button> | ||
| <button type="button" onClick={() => setWheel(!wheel)}> | ||
| toggle wheel ({String(wheel)}) | ||
| </button> | ||
| </p> | ||
|
|
||
| <hr /> | ||
| <h3>Uncontrolled</h3> | ||
| <InputNumber | ||
| type="spinner" | ||
| style={{ width: 100 }} | ||
| onChange={onChange} | ||
| min={-99} | ||
| max={99} | ||
| defaultValue={33} | ||
| /> | ||
|
|
||
| <hr /> | ||
| <h3>!changeOnBlur</h3> | ||
| <InputNumber | ||
| type="spinner" | ||
| style={{ width: 100 }} | ||
| min={-9} | ||
| max={9} | ||
| defaultValue={10} | ||
| onChange={onChange} | ||
| changeOnBlur={false} | ||
| /> | ||
| </div> | ||
| ); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,3 +52,7 @@ nav: | |
| ## focus | ||
|
|
||
| <code src="./demo/focus.tsx"></code> | ||
|
|
||
| ## spinner | ||
|
|
||
| <code src="./demo/spinner.tsx"></code> | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,19 +16,17 @@ const STEP_DELAY = 600; | |||||||||||||||||
|
|
||||||||||||||||||
| export interface StepHandlerProps { | ||||||||||||||||||
| prefixCls: string; | ||||||||||||||||||
| upNode?: React.ReactNode; | ||||||||||||||||||
| downNode?: React.ReactNode; | ||||||||||||||||||
| upDisabled?: boolean; | ||||||||||||||||||
| downDisabled?: boolean; | ||||||||||||||||||
| action: 'up' | 'down'; | ||||||||||||||||||
| children?: React.ReactNode; | ||||||||||||||||||
| disabled?: boolean; | ||||||||||||||||||
| onStep: (up: boolean, emitter: 'handler' | 'keyboard' | 'wheel') => void; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| export default function StepHandler({ | ||||||||||||||||||
| prefixCls, | ||||||||||||||||||
| upNode, | ||||||||||||||||||
| downNode, | ||||||||||||||||||
| upDisabled, | ||||||||||||||||||
| downDisabled, | ||||||||||||||||||
| action, | ||||||||||||||||||
| children, | ||||||||||||||||||
| disabled, | ||||||||||||||||||
| onStep, | ||||||||||||||||||
| }: StepHandlerProps) { | ||||||||||||||||||
| // ======================== Step ======================== | ||||||||||||||||||
|
|
@@ -45,15 +43,15 @@ export default function StepHandler({ | |||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| // We will interval update step when hold mouse down | ||||||||||||||||||
| const onStepMouseDown = (e: React.MouseEvent, up: boolean) => { | ||||||||||||||||||
| const onStepMouseDown = (e: React.MouseEvent) => { | ||||||||||||||||||
| e.preventDefault(); | ||||||||||||||||||
| onStopStep(); | ||||||||||||||||||
|
|
||||||||||||||||||
| onStepRef.current(up, 'handler'); | ||||||||||||||||||
| onStepRef.current(action === 'up', 'handler'); | ||||||||||||||||||
|
|
||||||||||||||||||
| // Loop step for interval | ||||||||||||||||||
| function loopStep() { | ||||||||||||||||||
| onStepRef.current(up, 'handler'); | ||||||||||||||||||
| onStepRef.current(action === 'up', 'handler'); | ||||||||||||||||||
|
|
||||||||||||||||||
| stepTimeoutRef.current = setTimeout(loopStep, STEP_INTERVAL); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
@@ -75,11 +73,8 @@ export default function StepHandler({ | |||||||||||||||||
| // ======================= Render ======================= | ||||||||||||||||||
| const handlerClassName = `${prefixCls}-handler`; | ||||||||||||||||||
|
|
||||||||||||||||||
| const upClassName = clsx(handlerClassName, `${handlerClassName}-up`, { | ||||||||||||||||||
| [`${handlerClassName}-up-disabled`]: upDisabled, | ||||||||||||||||||
| }); | ||||||||||||||||||
| const downClassName = clsx(handlerClassName, `${handlerClassName}-down`, { | ||||||||||||||||||
| [`${handlerClassName}-down-disabled`]: downDisabled, | ||||||||||||||||||
| const className = clsx(handlerClassName, `${handlerClassName}-up`, { | ||||||||||||||||||
| [`${handlerClassName}-${action}-disabled`]: disabled, | ||||||||||||||||||
| }); | ||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||
|
|
||||||||||||||||||
| // fix: https://github.com/ant-design/ant-design/issues/43088 | ||||||||||||||||||
|
|
@@ -96,30 +91,23 @@ export default function StepHandler({ | |||||||||||||||||
| onMouseLeave: safeOnStopStep, | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| return ( | ||||||||||||||||||
| <span | ||||||||||||||||||
| {...sharedHandlerProps} | ||||||||||||||||||
| onMouseDown={(e) => { | ||||||||||||||||||
| onStepMouseDown(e); | ||||||||||||||||||
| }} | ||||||||||||||||||
|
Comment on lines
+103
to
+105
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 在交互处理器中检查 disabled 状态。 当 应用此 diff 添加 disabled 检查: <span
{...sharedHandlerProps}
onMouseDown={(e) => {
- onStepMouseDown(e);
+ if (!disabled) {
+ onStepMouseDown(e);
+ }
}}
aria-label={isUpAction ? 'Increase Value' : 'Decrease Value'}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
| aria-label={action === 'up' ? 'Increase Value' : 'Decrease Value'} | ||||||||||||||||||
| aria-disabled={disabled} | ||||||||||||||||||
| className={className} | ||||||||||||||||||
| > | ||||||||||||||||||
| {children || <span unselectable="on" className={`${prefixCls}-handler-${action}-inner`} />} | ||||||||||||||||||
| </span> | ||||||||||||||||||
| ); | ||||||||||||||||||
|
|
||||||||||||||||||
| return ( | ||||||||||||||||||
| <div className={clsx(`${handlerClassName}-wrap`, classNames?.actions)} style={styles?.actions}> | ||||||||||||||||||
| <span | ||||||||||||||||||
| {...sharedHandlerProps} | ||||||||||||||||||
| onMouseDown={(e) => { | ||||||||||||||||||
| onStepMouseDown(e, true); | ||||||||||||||||||
| }} | ||||||||||||||||||
| aria-label="Increase Value" | ||||||||||||||||||
| aria-disabled={upDisabled} | ||||||||||||||||||
| className={upClassName} | ||||||||||||||||||
| > | ||||||||||||||||||
| {upNode || <span unselectable="on" className={`${prefixCls}-handler-up-inner`} />} | ||||||||||||||||||
| </span> | ||||||||||||||||||
| <span | ||||||||||||||||||
| {...sharedHandlerProps} | ||||||||||||||||||
| onMouseDown={(e) => { | ||||||||||||||||||
| onStepMouseDown(e, false); | ||||||||||||||||||
| }} | ||||||||||||||||||
| aria-label="Decrease Value" | ||||||||||||||||||
| aria-disabled={downDisabled} | ||||||||||||||||||
| className={downClassName} | ||||||||||||||||||
| > | ||||||||||||||||||
| {downNode || <span unselectable="on" className={`${prefixCls}-handler-down-inner`} />} | ||||||||||||||||||
| </span> | ||||||||||||||||||
| // | ||||||||||||||||||
| </div> | ||||||||||||||||||
| ); | ||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||
| } | ||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.