AckerApple / angular-file

Angular components for user file select, drop, and more
http://ackerapple.github.io/angular-file/
MIT License
128 stars 40 forks source link

File attributes are set on the `label` element when host element is not already a file input #98

Closed qkevinto closed 3 years ago

qkevinto commented 3 years ago

createFileElm does not return an input element but rather the label:

createFileElm({ change }) {
    const label = createInvisibleFileInputWrap();
    ...
    return this.element.nativeElement.appendChild(label); // put on html stage
}

...

export const createInvisibleFileInputWrap = function () {
    var fileElem = createFileInput();
    var label = document.createElement('label');
    ...
    return label;
};

so for instances where the host element is not already an input:

paramFileElm() {
    ...
    return this.fileElm = this.createFileElm({
        change: this.changeFn.bind(this)
    });
}

the paramFileElm is actually a label and this becomes a problem when setting attributes like multiple and others that relies on paramFileElm as those attributes end up on the label rather than the file input:

if (this.multiple) {
    this.paramFileElm().setAttribute('multiple', this.multiple);
}
...
if (changes.accept) {
    this.paramFileElm().setAttribute('accept', changes.accept.currentValue || '*');
}
AckerApple commented 3 years ago

Awesome report. Will review further and act upon within 5 days. A PR from you would make things move along faster

qkevinto commented 3 years ago

Awesome report. Will review further and act upon within 5 days. A PR from you would make things move along faster

Done đŸ˜„

AckerApple commented 3 years ago

Aquire 3.6.0