Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

fix(button): Support anchor and button HTML attributes (#679) #680

Merged
merged 1 commit into from Feb 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions packages/button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@ const BUTTON_CLASS_NAME = 'mdc-button__icon';

type ButtonTypes = HTMLAnchorElement | HTMLButtonElement;

export interface ButtonProps<T extends ButtonTypes> extends Ripple.InjectedProps<T>, React.HTMLAttributes<T> {
raised?: boolean;
unelevated?: boolean;
outlined?: boolean;
dense?: boolean;
disabled?: boolean;
className?: string;
icon?: React.ReactElement<React.HTMLProps<HTMLOrSVGElement>>;
href?: string;
trailingIcon?: React.ReactElement<React.HTMLProps<HTMLOrSVGElement>>;
export interface ButtonProps<T extends ButtonTypes>
extends Ripple.InjectedProps<T>, React.AnchorHTMLAttributes<T>, React.ButtonHTMLAttributes<T> {
raised?: boolean;
unelevated?: boolean;
outlined?: boolean;
dense?: boolean;
disabled?: boolean;
className?: string;
icon?: React.ReactElement<React.HTMLProps<HTMLOrSVGElement>>;
href?: string;
trailingIcon?: React.ReactElement<React.HTMLProps<HTMLOrSVGElement>>;
}

export const Button = <T extends ButtonTypes>(
Expand Down
10 changes: 10 additions & 0 deletions test/unit/button/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ test('renders a button with an anchor tag', () => {
assert.equal(wrapper.type(), 'a');
});

test('renders a button with a button attribute', () => {
const wrapper = shallow(<Button type='submit' />);
assert.equal(wrapper.prop('type'), 'submit');
});

test('renders a button with an anchor attribute', () => {
const wrapper = shallow(<Button download />);
assert.equal(wrapper.prop('download'), true);
});

test('default initRipple function', () => {
const initRipple = coerceForTesting<(surface: HTMLButtonElement) => {}>(td.func());
mount(<Button initRipple={initRipple} />);
Expand Down