Skip to content

Commit

Permalink
feat(MdFile): Support with field variants (#1662)
Browse files Browse the repository at this point in the history
* feat(MdFile): Support with field variants

* docs(MdFile): Support with field variants
  • Loading branch information
shafimsp authored and marcosmoura committed May 13, 2018
1 parent c502a16 commit fbf6d2a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/app/pages/Components/File/examples/FileField.vue
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
<template>
<div>
<md-field>
<md-icon md-file-trigger>attach_file</md-icon>
<label>Single</label>
<md-file v-model="single" />
</md-field>

<md-field>
<md-icon md-file-trigger>attach_file</md-icon>
<label>Upload files</label>
<md-file v-model="placeholder" placeholder="A nice input placeholder" />
</md-field>

<md-field>
<md-icon md-file-trigger>attach_file</md-icon>
<label>Disabled</label>
<md-file v-model="disabled" disabled/>
</md-field>

<md-field>
<md-icon md-file-trigger>attach_file</md-icon>
<label>Initial value</label>
<md-file v-model="initial" />
</md-field>

<md-field>
<md-icon md-file-trigger>attach_file</md-icon>
<label>Multiple</label>
<md-file v-model="multiple" multiple />
</md-field>

<md-field>
<md-icon md-file-trigger>attach_file</md-icon>
<label>Only images</label>
<md-file v-model="single" accept="image/*" />
</md-field>
Expand Down
27 changes: 25 additions & 2 deletions src/components/MdField/MdFile/MdFile.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<template>
<div class="md-file">
<md-file-icon @click.native="openPicker" />

<input
class="md-input"
readonly
Expand Down Expand Up @@ -31,6 +29,11 @@
},
name: String
},
data () {
return {
triggerEl: null
}
},
mixins: [MdFieldMixin],
inject: ['MdField'],
methods: {
Expand Down Expand Up @@ -73,8 +76,20 @@
created () {
this.MdField.file = true
},
mounted () {
this.$nextTick().then(() => {
this.triggerEl = this.MdField.$el.querySelector('[md-file-trigger]')
if (this.triggerEl) {
this.triggerEl.addEventListener('click', this.openPicker)
}
})
},
beforeDestroy () {
this.MdField.file = false
if (this.triggerEl) {
this.triggerEl.removeEventListener('click', this.openPicker)
}
}
}
</script>
Expand All @@ -99,4 +114,12 @@
cursor: pointer;
}
}
.md-field {
&.md-has-file {
[md-file-trigger] {
cursor: pointer;
}
}
}
</style>

1 comment on commit fbf6d2a

@marcosmoura
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was reverted. Due to the new changes on Material Design guidelines, this will no longer be applied.

Please sign in to comment.