danawoodman / react-fontawesome

A React Font Awesome component.
https://www.npmjs.com/package/react-fontawesome
MIT License
667 stars 72 forks source link

Displaying with no dimensions #53

Closed jayqui closed 7 years ago

jayqui commented 7 years ago

I feel like this is an ignorant question, but I can't seem to get react-fontawesome working correctly.

As you'll see from this screenshot, the expected <span> with fa fa-search classes resulting from my <FontAwesome /> component does show up in the DOM tree in my Chrome devtools. However, Chrome displays it as having dimensions of 0 x 0, even if I try to force it to have a determinate width and height.

image

I'm inside a create-react-app, and the component in question looks like this:

ControlPanel.js

import React, { Component } from 'react';
import FontAwesome from 'react-fontawesome';

import './ControlPanel.css';

export default class ControlPanel extends Component {
  render() {
    return (
      <div className='control-panel'>
        <FontAwesome
          name='search'
          size='2x'
          style={{ textShadow: '0 1px 0 rgba(0, 0, 0, 0.1)' }}
        />
        <input
          className='control-panel-filter'
          type='text'
          placeholder='search'
          onChange={this.props.handleQuery} />
      </div>
    );
  }
}

package.json

{
  "name": "experiment-6-18",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "classnames": "^2.2.5",
    "react": "15.6.1",
    "react-dom": "15.6.1",
    "react-fontawesome": "^1.6.1",
    "react-router-dom": "^4.1.2"
  },
  "devDependencies": {
    "react-scripts": "1.0.7"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}
danawoodman commented 7 years ago

Did you include the font awesome CSS somewhere as stated in the readme? That's probably it 😉

jayqui commented 7 years ago

Yes indeed! Given I'm using yarn with es6 import (given I'm using the latest create-react-app framework), the following was the remedy:

yarn add font-awesome

ControlPanel.js

import 'font-awesome/css/font-awesome.css';
danawoodman commented 7 years ago

😜 Thought so! Glad you got it working 👍