Skip to content

Commit

Permalink
fix(button): fix gradient style applied to anchor buttons due to type
Browse files Browse the repository at this point in the history
It looks like it affects only Safari. There, anchor buttons would appear with a different style and
some kind of gradient due to it keeping the type="button" as default. This commit fixes it and there
should be no breaking changes for regular button and input buttons.

fix #7
  • Loading branch information
estevanmaito committed Aug 8, 2020
1 parent 3d735df commit 131bd69
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 6 additions & 0 deletions __tests__/Button.test.js
Expand Up @@ -38,6 +38,12 @@ describe('Base Button', () => {
expect(wrapper.find('a')).toHaveLength(1)
})

it('should not contain type for anchor element', () => {
const wrapper = mount(<Button tag="a" />)

expect(wrapper.find('a').getDOMNode().getAttribute('type')).toBeNull()
})

it('should render its children', () => {
const wrapper = mount(<Button>Hi</Button>)

Expand Down
9 changes: 6 additions & 3 deletions src/Button.js
Expand Up @@ -12,7 +12,6 @@ const Button = React.forwardRef(function Button(props, ref) {
iconRight,
disabled,
size,
type,
layout,
block,
className,
Expand All @@ -23,6 +22,11 @@ const Button = React.forwardRef(function Button(props, ref) {
theme: { button },
} = useContext(ThemeContext)

// Fix https://github.com/estevanmaito/windmill-react-ui/issues/7
if ((tag === 'button' || tag === 'input') && !other.type) {
other.type = 'button'
}

function hasIcon() {
return !!icon || !!iconLeft || !!iconRight
}
Expand Down Expand Up @@ -100,7 +104,7 @@ const Button = React.forwardRef(function Button(props, ref) {
const iconRightStyles = classNames(iconStyle, children ? button.icon.right : '')

return (
<Component className={cls} ref={ref} disabled={disabled} type={type} {...other}>
<Component className={cls} ref={ref} disabled={disabled} {...other}>
{(icon || iconLeft) && <IconLeft className={iconLeftStyles} aria-hidden="true" />}
{children}
{iconRight && <IconRight className={iconRightStyles} aria-hidden="true" />}
Expand Down Expand Up @@ -128,7 +132,6 @@ Button.defaultProps = {
layout: 'primary',
block: false,
disabled: false,
type: 'button',
}

export default Button

0 comments on commit 131bd69

Please sign in to comment.