Skip to content

Commit beb4f7e

Browse files
committed
Dev warning when rendering a link
1 parent e81b5b4 commit beb4f7e

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

packages/react/src/use-button/useButton.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as React from 'react';
33
import { isHTMLElement } from '@floating-ui/utils/dom';
44
import { useStableCallback } from '@base-ui-components/utils/useStableCallback';
55
import { error } from '@base-ui-components/utils/error';
6+
import { warn } from '@base-ui-components/utils/warn';
67
import { useIsoLayoutEffect } from '@base-ui-components/utils/useIsoLayoutEffect';
78
import { makeEventPreventable, mergeProps } from '../merge-props';
89
import { useCompositeRootContext } from '../composite/root/CompositeRootContext';
@@ -53,6 +54,10 @@ export function useButton(parameters: useButton.Parameters = {}): useButton.Retu
5354
error(
5455
'A component that acts as a button was rendered as a native <button>, which does not match the default. Ensure that the element passed to the `render` prop of the component is not a real <button>, or set the `nativeButton` prop on the component to `true`.',
5556
);
57+
} else if (elementRef.current.tagName === 'A') {
58+
warn(
59+
'A component that acts as a button was rendered as an <a> tag, which could cause usability issues for keyboard and assistive tech users. Prefer using `<a>` directly.',
60+
);
5661
}
5762
}, [isNativeButton]);
5863
}

0 commit comments

Comments
 (0)