fluentui icon indicating copy to clipboard operation
fluentui copied to clipboard

How to use a primary button with an icon?

Open mizzle-mo opened this issue 10 years ago • 4 comments

If I am reading the documentation right, I can only add an icon to hero or command buttons. So this is likely by design. Is there a way I can have the ButtonType.primary button look and have an icon?

I tried this:

import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { Button, ButtonType } from 'office-ui-fabric-react/lib/Button';

const MyPage = () => (<div><Button icon="personAdd" buttonType={ ButtonType.primary }>I am a button.</Button></div>);

ReactDOM.render(<MyPage />, document.getElementById("content") as Element);

mizzle-mo avatar Jul 21 '16 22:07 mizzle-mo

Thanks for reporting.

So my 2c here is that we should really not have an Icon button, but instead just make the icon work with any button style. I think that's what you were expecting. We can fix that. We are going to go through a gutting of the Fabric component css, and in that process can re-evaluate the styling that's causing problems (I tried your scenario, and the icon is being hidden somewhere in the Fabric css.)

But right now the button is also pretty flexible. You can throw anything you want into a button, but you may have to adjust its css appropriately. Example:

<Button className='my-Button' buttonType={ ButtonType.primary } title='Star' ariaLabel='Take a star'>
  <i className='ms-Icon ms-Icon-star' />
  <span>I am a button.</span>
</Button>
.my-Button {
  .ms-Icon {
    margin-right: 4px;
  }
}

dzearing avatar Jul 22 '16 00:07 dzearing

@dzearing Thank you for the rapid response. Yes, that is what I was expecting at first glance, that I could just add an icon to any button. Would definitely like to see it work that way.

Thanks for providing the sample. That works great!

mizzle-mo avatar Jul 22 '16 15:07 mizzle-mo

There is now an icon button.

dzearing avatar Nov 18 '16 01:11 dzearing

Buttons having elements inside them seem to have their height reduced. Button text centering seems a little off too. http://codepen.io/anon/pen/ggVpxJ?editors=0110#anon-login

approots avatar Feb 21 '17 00:02 approots