Skip to content

Commit

Permalink
Merge pull request #2082 from bem/gela-d-attach
Browse files Browse the repository at this point in the history
Attach: extend api
  • Loading branch information
Gela committed Feb 1, 2019
2 parents fe7f8df + dd4f328 commit 30eb4ae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
12 changes: 10 additions & 2 deletions common.blocks/attach/attach.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ provide(bemDom.declBlock(this.name, Control, /** @lends attach.prototype */{
return this._clear(data);
},

/**
* Returns file element
* @returns {attach__file}
*/
getFileElem : function() {
return this.findChildElem('file');
},

_clear : function(data) {
var control = this._elem('control').domElem,
name = control.attr('name'),
Expand All @@ -47,7 +55,7 @@ provide(bemDom.declBlock(this.name, Control, /** @lends attach.prototype */{
(tabIndex? ' tabindex="' + tabIndex + '"' : '') +
'/>');

bemDom.destruct(this.findChildElem('file').domElem);
bemDom.destruct(this.getFileElem().domElem);

this.domElem.append(this._elem('no-file').domElem); // use append because only detached before

Expand Down Expand Up @@ -75,7 +83,7 @@ provide(bemDom.declBlock(this.name, Control, /** @lends attach.prototype */{
_updateFileElem : function() {
var fileName = extractFileNameFromPath(this.getVal());

this.findChildElem('file') && bemDom.destruct(this._elem('file').domElem);
this.getFileElem() && bemDom.destruct(this._elem('file').domElem);

bemDom.append(
this.domElem,
Expand Down
5 changes: 5 additions & 0 deletions common.blocks/attach/attach.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ describe('attach', function() {
setFile('\\usr\\local\\file.png');
attach._elem('text').domElem.text().should.be.equal('file.png');
});

it('should have file element', function() {
setFile('file.png');
Boolean(attach.getFileElem()).should.be.true;
});
});

describe('clear', function() {
Expand Down

0 comments on commit 30eb4ae

Please sign in to comment.