Skip to content

Commit f762e28

Browse files
lisalupimatthprost
authored andcommitted
fix: navigation active (#5270)
1 parent 631550b commit f762e28

File tree

7 files changed

+41
-1073
lines changed

7 files changed

+41
-1073
lines changed

.changeset/rude-paths-stick.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@ultraviolet/plus": patch
3+
---
4+
5+
`Navigation`: isActive should work when the Item is wrapped in a Link/NavLink (React rooter)

packages/plus/src/components/Navigation/components/Item.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ const StyledMenuItem = styled(Menu.Item, {
116116
}
117117
118118
${StyledBadge} {
119-
opacity: ${({ isPinnable, pinnedFeature }) => (isPinnable && pinnedFeature ? 0 : 1)};
119+
opacity: ${({ isPinnable, pinnedFeature }) =>
120+
isPinnable && pinnedFeature ? 0 : 1};
120121
}
121122
}
122123
`
@@ -265,6 +266,10 @@ const ContainerCategoryIcon = styled(Stack)`
265266

266267
type ItemType = 'default' | 'pinned' | 'pinnedGroup'
267268

269+
type LinkProps = {
270+
to: string
271+
children?: { props: ItemProps }
272+
}
268273
type ItemProps = {
269274
children?: ReactNode
270275
/**
@@ -433,9 +438,18 @@ export const Item = memo(
433438
if (!children) return false
434439

435440
return (
436-
Children.map(children, child =>
437-
isValidElement<ItemProps>(child) ? child.props?.active : false,
438-
) as boolean[]
441+
Children.map(children, child => {
442+
if (isValidElement<ItemProps | LinkProps>(child)) {
443+
// In case the Item is wrapped in a link
444+
if ('to' in child.props) {
445+
return child.props.children?.props.active
446+
}
447+
448+
return child.props.active
449+
}
450+
451+
return null
452+
}) as boolean[]
439453
).includes(true)
440454
}, [children])
441455

packages/ui/src/components/NumberInput/index.tsx

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -298,37 +298,31 @@ export const NumberInput = forwardRef(
298298
[localRef, min, onChange],
299299
)
300300

301-
const isMinusDisabled = useMemo(
302-
() => {
303-
if (!localRef?.current?.value || localRef?.current?.value === '') {
304-
return false
305-
}
301+
const isMinusDisabled = useMemo(() => {
302+
if (!localRef?.current?.value || localRef?.current?.value === '') {
303+
return false
304+
}
306305

307-
const numericValue = Number(localRef?.current?.value)
308-
if (Number.isNaN(numericValue)) return false
306+
const numericValue = Number(localRef?.current?.value)
307+
if (Number.isNaN(numericValue)) return false
309308

310-
const minValue = typeof min === 'number' ? min : Number(min)
309+
const minValue = typeof min === 'number' ? min : Number(min)
311310

312-
return Number.isNaN(numericValue) || numericValue <= minValue
313-
}, // eslint-disable-next-line react-hooks/exhaustive-deps
314-
[localRef?.current?.value, min],
315-
)
311+
return Number.isNaN(numericValue) || numericValue <= minValue
312+
}, [localRef?.current?.value, min])
316313

317-
const isPlusDisabled = useMemo(
318-
() => {
319-
if (!localRef?.current?.value || localRef?.current?.value === '') {
320-
return false
321-
}
314+
const isPlusDisabled = useMemo(() => {
315+
if (!localRef?.current?.value || localRef?.current?.value === '') {
316+
return false
317+
}
322318

323-
const numericValue = Number(localRef?.current?.value)
324-
if (Number.isNaN(numericValue)) return false
319+
const numericValue = Number(localRef?.current?.value)
320+
if (Number.isNaN(numericValue)) return false
325321

326-
const maxValue = typeof max === 'number' ? max : Number(max)
322+
const maxValue = typeof max === 'number' ? max : Number(max)
327323

328-
return numericValue >= maxValue
329-
}, // eslint-disable-next-line react-hooks/exhaustive-deps
330-
[localRef?.current?.value, max],
331-
)
324+
return numericValue >= maxValue
325+
}, [localRef?.current?.value, max])
332326

333327
const helperSentiment = useMemo(() => {
334328
if (error) {

0 commit comments

Comments
 (0)