Skip to content

Commit 043e283

Browse files
authored
Merge pull request #465 from dev-five-git/fix-props-warning-components
Fix Stepper component warning
2 parents 0236d36 + 295c3fc commit 043e283

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

.changeset/light-things-see.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@devup-ui/components': patch
3+
---
4+
5+
Fix component warning

.github/workflows/publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ jobs:
7070
node-version: 22
7171
cache: 'pnpm'
7272
- run: pnpm i
73+
- run: pnpm build
7374
- run: |
74-
pnpm build
7575
pnpm lint
7676
# rust coverage issue
7777
echo 'max_width = 100000' > .rustfmt.toml
@@ -83,8 +83,8 @@ jobs:
8383
echo 'merge_derives = true' >> .rustfmt.toml
8484
echo 'use_small_heuristics = "Default"' >> .rustfmt.toml
8585
cargo fmt
86-
pnpm test
8786
rm -rf .rustfmt.toml
87+
- run: pnpm test
8888
- name: Build Landing
8989
run: |
9090
pnpm -F components build-storybook

packages/components/src/components/Stepper/__tests__/index.browser.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('Stepper', () => {
1414
<Stepper>
1515
<StepperContainer>
1616
<StepperDecreaseButton />
17-
<StepperInput editable={false} />
17+
<StepperInput />
1818
<StepperIncreaseButton />
1919
</StepperContainer>
2020
</Stepper>,
@@ -24,7 +24,7 @@ describe('Stepper', () => {
2424

2525
it('should throw error if children are used outside of StepperProvider', () => {
2626
expect(() => {
27-
render(<StepperInput editable={false} />)
27+
render(<StepperInput />)
2828
}).toThrow('useStepper must be used within a StepperProvider')
2929
})
3030

packages/components/src/components/Stepper/index.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,7 @@ function StepperIncreaseButton({ ...props }: ComponentProps<typeof Button>) {
131131
)
132132
}
133133

134-
interface StepperInputProps extends ComponentProps<typeof Input> {
135-
editable?: boolean
136-
}
134+
type StepperInputProps = ComponentProps<typeof Input>
137135

138136
function StepperInput({ className, ...props }: StepperInputProps) {
139137
const { value, setValue, type } = useStepper()
@@ -144,12 +142,15 @@ function StepperInput({ className, ...props }: StepperInputProps) {
144142
h: 'fit-content',
145143
styleOrder: 3,
146144
})
147-
const editable = type === 'input'
148-
const Comp = editable ? Input : 'div'
145+
const isInput = type === 'input'
146+
const Comp = isInput ? Input : 'div'
147+
if (isInput) {
148+
// div tag doesn't support allowClear prop
149+
Object.assign(props, { allowClear: false })
150+
}
149151

150152
return (
151153
<Comp
152-
allowClear={false}
153154
aria-label="Stepper value"
154155
className={clsx(
155156
css({
@@ -163,17 +164,20 @@ function StepperInput({ className, ...props }: StepperInputProps) {
163164
},
164165
},
165166
}),
166-
!editable && notEditableClass,
167+
!isInput && notEditableClass,
167168
className,
168169
)}
169170
dangerouslySetInnerHTML={
170-
editable ? undefined : { __html: Number(value).toString() }
171+
isInput ? undefined : { __html: Number(value).toString() }
171172
}
172173
data-value={value}
173-
onChange={(e) => setValue(Number(e.target.value))}
174-
readOnly={!editable}
174+
onChange={(e) => {
175+
setValue(Number(e.target.value))
176+
}}
177+
readOnly={!isInput}
175178
type="number"
176-
value={value}
179+
// Fix prefix 0 issue
180+
value={value.toString()}
177181
{...props}
178182
/>
179183
)

0 commit comments

Comments
 (0)