์ด๊ฒ์ผ๋ก...
<FlatButton primary={true} label="Choose an Image">
<input type="file" id="imageButton"></input>
</FlatButton>
์ค์ ๋ก dom์์ ํ์ผ ์ ๋ ฅ ํ๋๋ฅผ ๋ ๋๋งํ์ง ์๋ ๋ฒํผ์ผ๋ก ๋๋ฉ๋๋ค(๋ฒํผ์ ํด๋ฆญํด๋ ํ์ผ ๋ํ ์์๊ฐ ์ด๋ฆฌ์ง ์์).
๋ฒ์ 0.7.5.
@nschaubeck ๋ฌธ์ ์ฌ์ดํธ์ ๋ฒํผ์ด ์๋ํฉ๋๊น?
@hai-cea ๋ค ๊ทธ๋ ์ต๋๋ค. ๋ฒํผ ์์๊ฐ ์์์ ๋ ๋๋งํ์ง ์๋ ๊ฒ์ฒ๋ผ DOM์ <input>
์์๋ ์๋ ๊ฒ ๊ฐ์์ต๋๋ค.
์ ๋ ์ด ๋ฌธ์ ๊ฐ ์์ต๋๋ค. @nschaubeck ํด๊ฒฐ์ฑ ์ ์ฐพ์ ์ ์ด ์์ต๋๊น?
@e-monson ์ค์ ๋ก ์๋ฃจ์ ์ ์ฐพ์ ์ ์์์ต๋๋ค.
์ด๊ฒ์ ์๋ํฉ๋๋ค!
ํ์ ์คํ์ผ = {
์์์ด๋ฏธ์ง์
๋ ฅ: {
์ปค์: 'ํฌ์ธํฐ',
์์น: '์ ๋',
์๋จ: '0',
ํ๋จ: '0',
์ค๋ฅธ์ชฝ: '0',
์ผ์ชฝ: '0',
๋๋น: '100%',
๋ถํฌ๋ช
๋: '0'
}
}
<FlatButton label="Choose an Image" primary={true}>
<input id="imageButton" style={styles.exampleImageInput} type="file"></input>
</FlatButton>
@nikhildaga ๋ฒํผ์ ์ ๋ ฅ ํ๋๋ฅผ ๋ฐฐ์นํ๋ ๊ฒ์ด W3C ์ฌ์์ ์ผ๋ถ๊ฐ ์๋๊ธฐ ๋๋ฌธ์ Chrome์์๋ง ์๋ํฉ๋๋ค.
๋ค๋ฅธ ์๋ฃจ์ ์ ๋ฒํผ์ด ์จ๊ฒจ์ง ์ ๋ ฅ ํ๋์ ํด๋ฆญ ์ด๋ฒคํธ๋ฅผ ๋ฐ์์ํค๋๋ก ํ๋ ๊ฒ์ ๋๋ค.
handleChange: function(e){
console.log(e.target.value)
},
_openFileDialog: function(){
var fileUploadDom = React.findDOMNode(this.refs.fileUpload);
fileUploadDom.click();
},
render: function() {
return (
<FlatButton
label="Upload file"
onClick={this._openFileDialog}/>
<input
ref="fileUpload"
type="file"
style={{"display" : "none"}}
onChange={this._handleChange}/>
);
}
์ด ๋ฌธ์ ๊ฐ ์ฌ์ ํ ์ฌ๋ฐ๋ฅด๊ฒ ์์ ๋์ง ์์ ๊ฒ์ผ๋ก ๋ํ๋ฌ์ต๋๋ค...
๋ฌธ์์์ ์ ์ํ ์๋ฃจ์
์ @Wofiel์ด ๋งํ ๋๋ก Chrome์์๋ง ์๋ํฉ๋๋ค. (๋ฒ ํ 15-0.2์์๋ ์ฌ์ ํ ๊ทธ๋ ์ต๋๋ค)
htmlFor
์ <FlatButton>
(๋๋ <RaisedButton>
)๋ก ์ค์ ํ๊ณ Id๋ฅผ ์
๋ ฅ ํ์ผ๋ก ์ค์ ํ๋ฉด ๊ทธ๊ฒ ๋ค์ง ์์๊น์? ์๋์ผ๋ก ํด๋ฆญ์ ํธ๋ฆฌ๊ฑฐํ ํ์๊ฐ ์์ต๋๋ค...
๋ ์ด๋ธ์ ๋ฒํผ์ ๋ํํ๋ ค๊ณ ์๋ํ์ง๋ง ๋ถํํ๋ ์๋ํ์ง ์์ต๋๋ค.
์ง๊ธ์ @Wofiel ์ด ์ต๊ณ ์ ์๋ฃจ์ ์ธ ๊ฒ ๊ฐ์ต๋๋ค.
๊ธฐ๋ณธ ์๋ฃจ์ ์ด ์์ ๋ ์ด๊ฒ์ ๋ซ๋ ์ด์
์๋ ํ์ธ์ @Wofiel ์ํ ๋น์ ์ฅ ๊ตฌ์ฑ ์์์์ ์ฐธ์กฐ์์ด์ด ๊ธฐ์ ์ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ์ ์ํฉ๋๊น?
@excalliburbd id์ Jquery๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค. ์๋ํด์ผ ํฉ๋๋ค.
@Birssan dom ์กฐ์ ๋ฐ์? ๊ด์ฐฎ์?
ํ์์๋ ์ถ์ฒํ์ง ์๊ฒ ์ง๋ง, ์ด ๊ฒฝ์ฐ์๋ ๊ด์ฐฎ์ ํด๋ฆญ ์ด๋ฒคํธ๋ฅผ ํธ๋ฆฌ๊ฑฐํ๋ ๊ฒ์ด๋ผ๊ณ ์๊ฐํฉ๋๋ค
@Wofiel As๋ ๋ฒ์ 15 ๋ฐ์์ผ๋ก ์ํํ ์ ์์ต๋๊น?
@Wofiel ์ด ์๋ฃจ์
console.log(e.target.value)
1๊ฐ ์์
C:\fakepath\imagefilename.png
์ต๊ณ ์ ์๋ฃจ์
์
e.target.files[0]
๋ค๋ฅธ ์ฌ๋์ด ์ด ๋ฌธ์ ์ ์ง๋ฉดํ๋ฉด RaisedButton
์ containerElement
๋ฅผ ์ค์ ํ์ฌ ์
๋ ฅ ์์๋ฅผ ์์์ผ๋ก ๊ฐ๋ ๋ฐ ๋ ์ ํฉํ ๊ฒ์ผ๋ก ์ค์ ํ ์ ์์ต๋๋ค. ์๋ฅผ ๋ค์ด ๋ ์ด๋ธ ;-)
<RaisedButton
containerElement='label' // <-- Just add me!
label='My Label'>
<input type="file" />
</RaisedButton>
@Thomas101 ๊ฐ์ฌํฉ๋๋ค! ๋ฐฉ๊ธ ์ด ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ผ๋ฉฐ ๊ทํ์ ์๋ฃจ์
์ด ์๋ํ๋ ๊ฒ ๊ฐ์ต๋๋ค.
์์ฒญ๋ :)
@Thomas101 ํ ๊ฐ์ฌํฉ๋๋ค. ์ด๊ฒ์ ๋ด ๋ฌธ์ ๋ ํด๊ฒฐํ์ต๋๋ค. ์ค์
@Thomas101 ๋ต๋ณ์ ๋ณด์ํ๊ธฐ๋ง ํ๋ฉด ๊ทธ์ ์์ ์ ๊ฐ์ ๊ตฌ์ฑ ์์๋ฅผ ์ ์ธํ ๋ RaisedButton์ด ๋ด๋ถ์ ํ์ผ ์
๋ ฅ์ผ๋ก ๋ ๋๋ง๋ฉ๋๋ค. ์ด๋ฅผ ๋ฐฉ์งํ๋ ค๋ฉด ํ์ผ ์
๋ ฅ ์คํ์ผ์ display: none
๋ก ์ค์ ํ๋ฉด ๋ฉ๋๋ค. :)
<RaisedButton
containerElement='label' // <-- Just add me!
label='My Label'>
<input type="file" style={{ display: 'none' }} />
</RaisedButton>
@andreyluiz ์ด๋ค ์ํฉ์์ ์๋ํ์ง ์๋์ง:
<RaisedButton label='My Label'>
<input type="file" />
</RaisedButton>
๋ฌธ์ ์ฌ์ดํธ ์์ ์์ ๋ฌธ์ ๋ฅผ ์ฐพ์ ์ ์์์ง๋ง ๋ถ๋ช ํ ๋ค๋ฅธ ๋ง์ ์ฌ๋๋ค์ด ์ด ๋ฌธ์ ๋ฅผ ๊ฐ์ง๊ณ ์์ต๋๋ค!
ํ์ผ ์ ๋ ฅ์ ์ ๊ณตํ ์ฝ๋๊ฐ ํ์๋์ง ์์์ผ ํฉ๋๊น?
์ด์ ํ๋ค. ์ ๊ฒฝ์ฐ์๋ material-ui ๋ฒํผ ๋ด๋ถ์ ํ์ผ ์ ๋ ฅ์ ๋ ๋๋งํฉ๋๋ค.
@andreyluiz ์, ๋ฌธ์ ์ฌ์ดํธ ์์ (http://www.material-ui.com/#/components/raised-button)์๋ <input>
๊ฐ ํ์๋์ง ์์ต๋๋ค. ์ด๋ค ๋ธ๋ผ์ฐ์ ๋ฐ ๋ฒ์ ์ผ๋ก ํ
์คํธํ๊ณ ์์ต๋๊น?
์ต์ ํฌ๋กฌ ๋ฒ์ .
๋๋ @andreyluiz ์ ๋์ํฉ๋๋ค. ๋ ๋ณด์ฌ์ฃผ์ง๋ง style={{display: 'none'}}
๋ฅผ ์ฌ์ฉํ๋ฉด ๋งค๋ ฅ์ฒ๋ผ ์๋ํฉ๋๋ค!
ํ ๋ฐ์ฌ
<RaisedButton
containerElement="label"
icon={<Icons.FileUpload />} // material-ui-icons
labelColor="white"
primary
style={{ minWidth: 40, width: 40 }}>
<input
onChange={e => this.upload(e.target.files[0])}
style={{ display: 'none' }}
type="file"
/>
</RaisedButton>
์์ ์๋ฃจ์ ์ด ๋ ์ด์ ์๋ํ์ง ์๋ ๊ฒ ๊ฐ์ต๋๋ค. ์๋ก์ด v1 ๋ฒ ํ ๋ธ๋์น๋ฅผ ์ฌ์ฉํ๊ณ ์๋๋ฐ ๋ค์์ด ์๋ํ์ง ์์ต๋๋ค.
<Button dense
containerElement="label"
label="label">
<input
onChange={e => this.upload(e.target.files[0])}
style={{display: 'none'}}
type="file"
/>
</Button>
์ฝ์์ ๋ค์ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
Warning: React does not recognize the `containerElement` prop on a DOM element.
If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase `containerelement` instead.
If you accidentally passed it from a parent component, remove it from the DOM element.
ํด๊ฒฐ ๋ฐฉ๋ฒ์ ์๋ ์ฌ๋์ด ์์ต๋๊น? ์ด์จ๋ ๊ทธ๋ฌํ ์ผ๋ฐ์ ์ธ ์ฌ์ฉ ์ฌ๋ก๋ ๊ธฐ๋ณธ์ ์ผ๋ก ์ง์๋์ด์ผ ํ์ง ์์ต๋๊น? (๋น ํดํน ๋ฐฉ์์ผ๋ก)
@AdityaAnand1 ๋ค์ ์ฝ๋๊ฐ ์๋ํด์ผ ํฉ๋๋ค.
<Button
raised
component="label" <---- use component instead of containerElement
color="primary"
className={buttonClassname}
disabled={this.state.loading}
onClick={this.handleButtonClick}
>
{'Upload'}
<FileUpload className={classes.rightIcon} />
<input
onChange={e => console.log(e.target.files[0])}
style={{ display: 'none' }}
type="file"
/>
</Button>
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
๋ค๋ฅธ ์ฌ๋์ด ์ด ๋ฌธ์ ์ ์ง๋ฉดํ๋ฉด
RaisedButton
์containerElement
๋ฅผ ์ค์ ํ์ฌ ์ ๋ ฅ ์์๋ฅผ ์์์ผ๋ก ๊ฐ๋ ๋ฐ ๋ ์ ํฉํ ๊ฒ์ผ๋ก ์ค์ ํ ์ ์์ต๋๋ค. ์๋ฅผ ๋ค์ด ๋ ์ด๋ธ ;-)