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

[Upload]headers support and input-number letters input #1553

Merged
merged 4 commits into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ exports[`center.jsx 1`] = `
class="t-space-item"
>
<div
class="t-input-number t-size-m t-input-number--row t-input-number--auto-width"
class="t-input-number t-size-m t-input-number--row"
style="width: 250px;"
>
<button
Expand All @@ -443,7 +443,7 @@ exports[`center.jsx 1`] = `
</svg>
</button>
<div
class="t-input__wrap t-input--auto-width"
class="t-input__wrap"
value=""
>
<div
Expand All @@ -456,11 +456,6 @@ exports[`center.jsx 1`] = `
type="text"
value=""
/>
<span
class="t-input__input-pre"
>
请输入
</span>
</div>
</div>
<button
Expand Down Expand Up @@ -528,6 +523,11 @@ exports[`center.jsx 1`] = `
</div>
</div>
<div
class="t-input__tips t-input__tips--error"
>
number can not be exceed maximum
</div>
</div>
<button
class="t-input-number__increase t-is-disabled t-button t-button--theme-default t-button--variant-outline t-button--shape-square"
Expand All @@ -547,11 +547,6 @@ exports[`center.jsx 1`] = `
/>
</svg>
</button>
<div
class="t-input__tips t-input__tips--error"
>
number can not be exceed maximum
</div>
</div>
</div>
</div>
Expand Down
5 changes: 3 additions & 2 deletions src/input-number/_example/center.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,16 @@ export default function InputNumberExample() {
console.info('enter', v, ctx);
}

// inputProps={{ tips }} 和 tips={tips} 均可
return (
<Space direction="vertical">
<InputNumber value={decimalValue} onChange={setDecimalValue} decimalPlaces={0} max={5} autoWidth />
<InputNumber value={value1} onChange={setValue1} step={0.1} max={5} style={{ width: 250 }} autoWidth />
<InputNumber value={value1} onChange={setValue1} step={0.1} max={5} style={{ width: 250 }} />
<InputNumber
value={value2}
max={15}
min={-2}
tips={tips}
inputProps={{ tips }}
suffix="个"
style={{ width: 300 }}
onChange={handleChange}
Expand Down
14 changes: 7 additions & 7 deletions src/input-number/useInputNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,13 @@ export default function useInputNumber<T extends InputNumberValue = InputNumberV

const getUserInput = (value: InputNumberValue) => {
if (!value && value !== 0) return '';
let inputStr = String(value);
let inputStr = value || value === 0 ? String(value) : '';
if (!inputRef.current.currentElement.contains?.(document.activeElement)) {
inputStr = String(
formatToNumber(inputStr, {
decimalPlaces: props.decimalPlaces,
largeNumber: props.largeNumber,
}),
);
const num = formatToNumber(inputStr, {
decimalPlaces: props.decimalPlaces,
largeNumber: props.largeNumber,
});
inputStr = num || num === 0 ? String(num) : '';
if (props.format) {
inputStr = String(props.format(value, { fixedNumber: inputStr }));
}
Expand Down Expand Up @@ -117,6 +116,7 @@ export default function useInputNumber<T extends InputNumberValue = InputNumberV
decimalPlaces: props.decimalPlaces,
largeNumber: props.largeNumber,
});
console.log(getUserInput(value), newValue);
if (newValue !== value && String(newValue) !== value) {
onChange(newValue as T, { type: 'blur', e: ctx.e });
}
Expand Down
2 changes: 2 additions & 0 deletions src/upload/hooks/useUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ export default function useUpload(props: TdUploadProps) {
setUploading(true);
upload({
action: props.action,
headers: props.headers,
withCredentials: props.withCredentials,
uploadedFiles: uploadValue,
toUploadFiles: files,
multiple: props.multiple,
Expand Down
2 changes: 1 addition & 1 deletion test/ssr/__snapshots__/ssr.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ exports[`ssr snapshot test renders ./src/input-number/_example/align.jsx correct

exports[`ssr snapshot test renders ./src/input-number/_example/auto-width.jsx correctly 1`] = `"<div class=\\"t-input-number t-size-m t-input-number--row t-input-number--auto-width\\"><button type=\\"button\\" class=\\"t-input-number__decrease t-button t-button--theme-default t-button--variant-outline t-button--shape-square\\"><svg fill=\\"none\\" viewBox=\\"0 0 16 16\\" width=\\"1em\\" height=\\"1em\\" class=\\"t-icon t-icon-remove t-size-m\\"><path fill=\\"currentColor\\" d=\\"M3.5 7.35h9v1.3h-9v-1.3z\\" fill-opacity=\\"0.9\\"></path></svg></button><div class=\\"t-input__wrap t-input--auto-width\\" value=\\"\\"><div class=\\"t-input t-size-m t-align-center t-is-default\\"><input type=\\"text\\" placeholder=\\"请输入\\" class=\\"t-input__inner\\" value=\\"\\" autoComplete=\\"off\\"/><span class=\\"t-input__input-pre\\">请输入</span></div></div><button type=\\"button\\" class=\\"t-input-number__increase t-button t-button--theme-default t-button--variant-outline t-button--shape-square\\"><svg fill=\\"none\\" viewBox=\\"0 0 16 16\\" width=\\"1em\\" height=\\"1em\\" class=\\"t-icon t-icon-add t-size-m\\"><path fill=\\"currentColor\\" d=\\"M7.35 8.65v3.85h1.3V8.65h3.85v-1.3H8.65V3.5h-1.3v3.85H3.5v1.3h3.85z\\" fill-opacity=\\"0.9\\"></path></svg></button></div>"`;

exports[`ssr snapshot test renders ./src/input-number/_example/center.jsx correctly 1`] = `"<div style=\\"gap:16px\\" class=\\"t-space t-space-vertical\\"><div class=\\"t-space-item\\"><div class=\\"t-input-number t-size-m t-input-number--row t-input-number--auto-width\\"><button type=\\"button\\" class=\\"t-input-number__decrease t-button t-button--theme-default t-button--variant-outline t-button--shape-square\\"><svg fill=\\"none\\" viewBox=\\"0 0 16 16\\" width=\\"1em\\" height=\\"1em\\" class=\\"t-icon t-icon-remove t-size-m\\"><path fill=\\"currentColor\\" d=\\"M3.5 7.35h9v1.3h-9v-1.3z\\" fill-opacity=\\"0.9\\"></path></svg></button><div class=\\"t-input__wrap t-input--auto-width\\" value=\\"\\"><div class=\\"t-input t-size-m t-align-center t-is-default\\"><input type=\\"text\\" placeholder=\\"请输入\\" class=\\"t-input__inner\\" value=\\"\\" autoComplete=\\"off\\"/><span class=\\"t-input__input-pre\\">请输入</span></div></div><button type=\\"button\\" class=\\"t-input-number__increase t-button t-button--theme-default t-button--variant-outline t-button--shape-square\\"><svg fill=\\"none\\" viewBox=\\"0 0 16 16\\" width=\\"1em\\" height=\\"1em\\" class=\\"t-icon t-icon-add t-size-m\\"><path fill=\\"currentColor\\" d=\\"M7.35 8.65v3.85h1.3V8.65h3.85v-1.3H8.65V3.5h-1.3v3.85H3.5v1.3h3.85z\\" fill-opacity=\\"0.9\\"></path></svg></button></div></div><div class=\\"t-space-item\\"><div class=\\"t-input-number t-size-m t-input-number--row t-input-number--auto-width\\" style=\\"width:250px\\"><button type=\\"button\\" class=\\"t-input-number__decrease t-button t-button--theme-default t-button--variant-outline t-button--shape-square\\"><svg fill=\\"none\\" viewBox=\\"0 0 16 16\\" width=\\"1em\\" height=\\"1em\\" class=\\"t-icon t-icon-remove t-size-m\\"><path fill=\\"currentColor\\" d=\\"M3.5 7.35h9v1.3h-9v-1.3z\\" fill-opacity=\\"0.9\\"></path></svg></button><div class=\\"t-input__wrap t-input--auto-width\\" value=\\"\\"><div class=\\"t-input t-size-m t-align-center t-is-default\\"><input type=\\"text\\" placeholder=\\"请输入\\" class=\\"t-input__inner\\" value=\\"\\" autoComplete=\\"off\\"/><span class=\\"t-input__input-pre\\">请输入</span></div></div><button type=\\"button\\" class=\\"t-input-number__increase t-button t-button--theme-default t-button--variant-outline t-button--shape-square\\"><svg fill=\\"none\\" viewBox=\\"0 0 16 16\\" width=\\"1em\\" height=\\"1em\\" class=\\"t-icon t-icon-add t-size-m\\"><path fill=\\"currentColor\\" d=\\"M7.35 8.65v3.85h1.3V8.65h3.85v-1.3H8.65V3.5h-1.3v3.85H3.5v1.3h3.85z\\" fill-opacity=\\"0.9\\"></path></svg></button></div></div><div class=\\"t-space-item\\"><div class=\\"t-input-number t-size-m t-input-number--row\\" style=\\"width:300px\\"><button type=\\"button\\" class=\\"t-input-number__decrease t-button t-button--theme-default t-button--variant-outline t-button--shape-square\\"><svg fill=\\"none\\" viewBox=\\"0 0 16 16\\" width=\\"1em\\" height=\\"1em\\" class=\\"t-icon t-icon-remove t-size-m\\"><path fill=\\"currentColor\\" d=\\"M3.5 7.35h9v1.3h-9v-1.3z\\" fill-opacity=\\"0.9\\"></path></svg></button><div class=\\"t-input__wrap\\" value=\\"\\"><div class=\\"t-input t-size-m t-align-center t-is-default t-input--suffix\\"><input type=\\"text\\" placeholder=\\"请输入\\" class=\\"t-input__inner\\" value=\\"\\" autoComplete=\\"off\\"/><div class=\\"t-input__suffix\\">个</div></div></div><button type=\\"button\\" class=\\"t-input-number__increase t-is-disabled t-button t-button--theme-default t-button--variant-outline t-button--shape-square\\"><svg fill=\\"none\\" viewBox=\\"0 0 16 16\\" width=\\"1em\\" height=\\"1em\\" class=\\"t-icon t-icon-add t-size-m\\"><path fill=\\"currentColor\\" d=\\"M7.35 8.65v3.85h1.3V8.65h3.85v-1.3H8.65V3.5h-1.3v3.85H3.5v1.3h3.85z\\" fill-opacity=\\"0.9\\"></path></svg></button></div></div></div>"`;
exports[`ssr snapshot test renders ./src/input-number/_example/center.jsx correctly 1`] = `"<div style=\\"gap:16px\\" class=\\"t-space t-space-vertical\\"><div class=\\"t-space-item\\"><div class=\\"t-input-number t-size-m t-input-number--row t-input-number--auto-width\\"><button type=\\"button\\" class=\\"t-input-number__decrease t-button t-button--theme-default t-button--variant-outline t-button--shape-square\\"><svg fill=\\"none\\" viewBox=\\"0 0 16 16\\" width=\\"1em\\" height=\\"1em\\" class=\\"t-icon t-icon-remove t-size-m\\"><path fill=\\"currentColor\\" d=\\"M3.5 7.35h9v1.3h-9v-1.3z\\" fill-opacity=\\"0.9\\"></path></svg></button><div class=\\"t-input__wrap t-input--auto-width\\" value=\\"\\"><div class=\\"t-input t-size-m t-align-center t-is-default\\"><input type=\\"text\\" placeholder=\\"请输入\\" class=\\"t-input__inner\\" value=\\"\\" autoComplete=\\"off\\"/><span class=\\"t-input__input-pre\\">请输入</span></div></div><button type=\\"button\\" class=\\"t-input-number__increase t-button t-button--theme-default t-button--variant-outline t-button--shape-square\\"><svg fill=\\"none\\" viewBox=\\"0 0 16 16\\" width=\\"1em\\" height=\\"1em\\" class=\\"t-icon t-icon-add t-size-m\\"><path fill=\\"currentColor\\" d=\\"M7.35 8.65v3.85h1.3V8.65h3.85v-1.3H8.65V3.5h-1.3v3.85H3.5v1.3h3.85z\\" fill-opacity=\\"0.9\\"></path></svg></button></div></div><div class=\\"t-space-item\\"><div class=\\"t-input-number t-size-m t-input-number--row\\" style=\\"width:250px\\"><button type=\\"button\\" class=\\"t-input-number__decrease t-button t-button--theme-default t-button--variant-outline t-button--shape-square\\"><svg fill=\\"none\\" viewBox=\\"0 0 16 16\\" width=\\"1em\\" height=\\"1em\\" class=\\"t-icon t-icon-remove t-size-m\\"><path fill=\\"currentColor\\" d=\\"M3.5 7.35h9v1.3h-9v-1.3z\\" fill-opacity=\\"0.9\\"></path></svg></button><div class=\\"t-input__wrap\\" value=\\"\\"><div class=\\"t-input t-size-m t-align-center t-is-default\\"><input type=\\"text\\" placeholder=\\"请输入\\" class=\\"t-input__inner\\" value=\\"\\" autoComplete=\\"off\\"/></div></div><button type=\\"button\\" class=\\"t-input-number__increase t-button t-button--theme-default t-button--variant-outline t-button--shape-square\\"><svg fill=\\"none\\" viewBox=\\"0 0 16 16\\" width=\\"1em\\" height=\\"1em\\" class=\\"t-icon t-icon-add t-size-m\\"><path fill=\\"currentColor\\" d=\\"M7.35 8.65v3.85h1.3V8.65h3.85v-1.3H8.65V3.5h-1.3v3.85H3.5v1.3h3.85z\\" fill-opacity=\\"0.9\\"></path></svg></button></div></div><div class=\\"t-space-item\\"><div class=\\"t-input-number t-size-m t-input-number--row\\" style=\\"width:300px\\"><button type=\\"button\\" class=\\"t-input-number__decrease t-button t-button--theme-default t-button--variant-outline t-button--shape-square\\"><svg fill=\\"none\\" viewBox=\\"0 0 16 16\\" width=\\"1em\\" height=\\"1em\\" class=\\"t-icon t-icon-remove t-size-m\\"><path fill=\\"currentColor\\" d=\\"M3.5 7.35h9v1.3h-9v-1.3z\\" fill-opacity=\\"0.9\\"></path></svg></button><div class=\\"t-input__wrap\\" value=\\"\\"><div class=\\"t-input t-size-m t-align-center t-is-default t-input--suffix\\"><input type=\\"text\\" placeholder=\\"请输入\\" class=\\"t-input__inner\\" value=\\"\\" autoComplete=\\"off\\"/><div class=\\"t-input__suffix\\">个</div></div></div><button type=\\"button\\" class=\\"t-input-number__increase t-is-disabled t-button t-button--theme-default t-button--variant-outline t-button--shape-square\\"><svg fill=\\"none\\" viewBox=\\"0 0 16 16\\" width=\\"1em\\" height=\\"1em\\" class=\\"t-icon t-icon-add t-size-m\\"><path fill=\\"currentColor\\" d=\\"M7.35 8.65v3.85h1.3V8.65h3.85v-1.3H8.65V3.5h-1.3v3.85H3.5v1.3h3.85z\\" fill-opacity=\\"0.9\\"></path></svg></button></div></div></div>"`;

exports[`ssr snapshot test renders ./src/input-number/_example/default.jsx correctly 1`] = `"<div class=\\"t-input-number t-size-m t-input-number--row\\"><button type=\\"button\\" class=\\"t-input-number__decrease t-button t-button--theme-default t-button--variant-outline t-button--shape-square\\"><svg fill=\\"none\\" viewBox=\\"0 0 16 16\\" width=\\"1em\\" height=\\"1em\\" class=\\"t-icon t-icon-remove t-size-m\\"><path fill=\\"currentColor\\" d=\\"M3.5 7.35h9v1.3h-9v-1.3z\\" fill-opacity=\\"0.9\\"></path></svg></button><div class=\\"t-input__wrap\\" value=\\"\\"><div class=\\"t-input t-size-m t-align-center t-is-default\\"><input type=\\"text\\" placeholder=\\"请输入\\" class=\\"t-input__inner\\" value=\\"\\" autoComplete=\\"off\\"/></div></div><button type=\\"button\\" class=\\"t-input-number__increase t-button t-button--theme-default t-button--variant-outline t-button--shape-square\\"><svg fill=\\"none\\" viewBox=\\"0 0 16 16\\" width=\\"1em\\" height=\\"1em\\" class=\\"t-icon t-icon-add t-size-m\\"><path fill=\\"currentColor\\" d=\\"M7.35 8.65v3.85h1.3V8.65h3.85v-1.3H8.65V3.5h-1.3v3.85H3.5v1.3h3.85z\\" fill-opacity=\\"0.9\\"></path></svg></button></div>"`;

Expand Down