MCPcopy Create free account
hub / github.com/adobe/react-spectrum / SideNavLink

Function SideNavLink

packages/dev/s2-docs/src/Nav.tsx:280–351  ·  view source on GitHub ↗
(props)

Source from the content-addressed store, hash-verified

278}
279
280export function SideNavLink(props) {
281 let linkRef = useRef<HTMLAnchorElement | null>(null);
282 let shouldAutoScrollOnMount = useRef(props.isSelected);
283 let selected = useContext(SideNavContext);
284 let {isExternal, ...linkProps} = props;
285
286 useEffect(() => {
287 let link = linkRef.current;
288 if (!link || !props.isSelected || !shouldAutoScrollOnMount.current) {
289 return;
290 }
291
292 shouldAutoScrollOnMount.current = false;
293 link.scrollIntoView({block: 'start'});
294 }, [props.isSelected]);
295
296 // oxlint-disable react/react-compiler
297 return (
298 <BaseLink
299 {...linkProps}
300 ref={linkRef}
301 target={isExternal ? '_blank' : undefined}
302 rel={isExternal ? 'noopener noreferrer' : undefined}
303 aria-current={props.isSelected || selected === props.href ? 'page' : undefined}
304 style={pressScale(linkRef)}
305 className={style({
306 ...focusRing(),
307 minHeight: 32,
308 boxSizing: 'border-box',
309 paddingX: 4,
310 // paddingY: centerPadding(),
311 display: 'flex',
312 alignItems: 'center',
313 gap: size(6),
314 font: 'ui',
315 fontWeight: {
316 default: 'normal',
317 isCurrent: 'bold'
318 },
319 textDecoration: 'none',
320 borderRadius: 'default',
321 transition: 'default',
322 scrollMarginTop: 64
323 })}>
324 {renderProps => (
325 <>
326 <span
327 className={style({
328 width: 2,
329 height: '[1lh]',
330 borderRadius: 'full',
331 transition: 'default',
332 backgroundColor: {
333 default: 'transparent',
334 isHovered: 'gray-400',
335 isCurrent: 'gray-800'
336 }
337 })(renderProps)}

Callers

nothing calls this directly

Calls 3

pressScaleFunction · 0.90
focusRingFunction · 0.90
sizeFunction · 0.90

Tested by

no test coverage detected