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

feat: add a possibility to use button component as link #327

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

karinamaulitova
Copy link
Contributor

  • update tests

@@ -35,6 +36,7 @@ function Button(props: ButtonProps, ref?: ForwardedRef<HTMLButtonElement>) {

return (
<ButtonStyle
as={(href ? 'a' : 'button') as React.ElementType}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to write href ? 'a' : null instead?

@@ -46,6 +48,7 @@ function Button(props: ButtonProps, ref?: ForwardedRef<HTMLButtonElement>) {
disabled={disabled || loading}
type='button'
ref={ref}
href={href}
Copy link
Contributor

@hexnickk4997 hexnickk4997 Jul 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not the best way from types standpoint, because <button> props and <a> props are different:

image

image

So basically we need that button should accept button props, and link should accept link props

cc @Jabher for discussion

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you suggest in this situation?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally like this approach, it is nice and minimal - by providing href you expect it to still be same component visually while making it a link. however, you are poiting different thing right - e.g. target attribute should be also supported here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, links and buttons have different props, and we probably should be able to specify which to use with link, otherwise there may be more prs and more if statements

@@ -12,6 +13,8 @@ exports[`renders correctly 1`] = `
background: transparent;
font-family: inherit;
font-weight: 700;
-webkit-text-decoration: none;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we have any prefixer for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a test snapshot, tests see prefixed code:)

...rest
} = props
} = props as ButtonButtonProps
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a disabled appearance of a button even if it is a link

Copy link
Contributor

@Jabher Jabher Jul 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ButtonButton feels like this, maybe better naming can be here (e.g. NativeButton):

@@ -11,7 +11,10 @@ export const useRipple: UseRipple = ({ onClick }) => {
const [ripple, setRipple] = useState<React.ReactNode | null>(null)

const handleClick = useCallback(
(event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
(
event: React.MouseEvent<HTMLAnchorElement, MouseEvent> &
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it & here? It's probably anchor element | button element

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works only with &

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants