2017-04-15 26 views
0

我有一種我正在應用於ActionSearch圖標的樣式,但不幸的是它不會通過。樣式不適用於MaterialUI中的SVGIcon React

不知道我可以寫更多的問題,我認爲這很簡單,但紙張獲取樣式時,圖標組件不。

任何想法爲什麼會這樣?

import React from 'react'; 
import Paper from 'material-ui/Paper'; 
import TextField from 'material-ui/TextField'; 
import IconButton from 'material-ui/IconButton'; 
import ActionSearch from 'material-ui/svg-icons/action/search'; 

const stylePaper = { 
    width: 400, 
    margin: '40px auto', 
    paddingBottom: 10, 
    textAlign: 'center', 
    display: 'inline-block' 
}; 

const styleIcon = { 
    position: 'absolute', 
    top: 20 
}; 

export default class Home extends React.Component { 
    constructor(props) { 
    super(props); 
    this.state = {value: ''}; 

    this.handleChange = this.handleChange.bind(this); 
    this.handleSubmit = this.handleSubmit.bind(this); 
    } 

    handleChange(event) { 
    this.setState({value: event.target.value}); 
    } 

    handleSubmit(event) { 
    alert('A name was submitted: ' + this.state.value); 
    event.preventDefault(); 
    } 

    render() { 
    return (
     <form onSubmit={this.handleSubmit}> 
     <Paper zDepth={2} style={stylePaper} > 
      <TextField 
      hintText="Type in brand, position or industry" 
      /> 
      <IconButton> 
      <ActionSearch style={styleIcon} /> 
      </IconButton> 
     </Paper> 
     </form> 
    ); 
    } 
} 

這裏是檢查圖像

ChromeDevTool debug

回答

1

由於SVG圖標已經被包裹在這個庫的組件(材料UI反應),我覺得你可以不適用你的風格對象直。從官方文檔中,我認爲您可能需要在組件中傳遞屬性「iconStyle」的樣式對象,請點擊此處http://www.material-ui.com/#/components/icon-button

+0

我認爲你是對的,只要我確認我會編輯答案(加入react-router):) – AlexGvozden

+1

就是這樣,謝謝你! – AlexGvozden