Skip to content

Commit

Permalink
fix: display drop label as disabled when max files reached (#379)
Browse files Browse the repository at this point in the history
cherry pick of: vaadin/web-components#2558
fixes warranty issue: vaadin/web-components#2431
  • Loading branch information
sissbruecker committed Sep 20, 2021
1 parent 087ba97 commit f28c07e
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/vaadin-upload.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
* `nodrop` | Set when drag and drop is disabled (e. g., on touch devices) | `:host`
* `dragover` | A file is being dragged over the element | `:host`
* `dragover-valid` | A dragged file is valid with `maxFiles` and `accept` criteria | `:host`
* `max-files-reached` | The maximum number of files that the user is allowed to add to the upload has been reached | `:host`
*
* See [ThemableMixin – how to apply styles for shadow parts](https://github.com/vaadin/vaadin-themable-mixin/wiki)
*
Expand Down Expand Up @@ -231,6 +232,7 @@
value: false,
notify: true,
readOnly: true,
reflectToAttribute: true,
computed: '_maxFilesAdded(maxFiles, files.length)'
},

Expand Down
9 changes: 9 additions & 0 deletions test/adding-files.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@
expect(clickSpy).not.to.be.called;
});

it('should set max-files-reached style attribute when max files added', () => {
upload.maxFiles = 0;

expect(upload.hasAttribute('max-files-reached')).to.be.true;
});

it('should not set max-files-reached style attribute when less than max files added', () => {
expect(upload.hasAttribute('max-files-reached')).to.be.false;
});
});

describeIf(!touchDevice, 'Dropping file', () => {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions test/visual/state.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>

<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="../../bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<script>
const theme = window.location.search.replace(/.*theme=(\w+).*/, '$1') || 'lumo';
document.write('<link rel="import" href="../../theme/' + theme + '/vaadin-upload.html">');
</script>
</head>

<body>

<div id="state-tests" style="display: inline-block">
<vaadin-upload id="max-files-reached">
</vaadin-upload>
</div>

<script>
window.addEventListener('WebComponentsReady', () => {
const stateMaxFilesReachedUpload = document.getElementById('max-files-reached');
stateMaxFilesReachedUpload.maxFiles = 1;
stateMaxFilesReachedUpload.files = [{name: 'Don Quixote.pdf'}];
});
</script>

</body>
8 changes: 8 additions & 0 deletions test/visual/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,12 @@ gemini.suite('vaadin-upload', function(rootSuite) {
});
});

['lumo', 'material'].forEach(theme => {
gemini.suite(`state-tests-${theme}`, function(suite) {
suite
.setUrl(`/state.html?theme=${theme}`)
.setCaptureElements('#state-tests')
.capture(`vaadin-upload`);
});
});
});
4 changes: 4 additions & 0 deletions theme/lumo/vaadin-upload-styles.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
color: var(--lumo-primary-text-color);
}

:host([max-files-reached]) [part='drop-label'] {
color: var(--lumo-disabled-text-color);
}

[part="drop-label-icon"] {
display: inline-block;
}
Expand Down
4 changes: 4 additions & 0 deletions theme/material/vaadin-upload-styles.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
color: var(--material-primary-text-color);
}

:host([max-files-reached]) [part='drop-label'] {
color: var(--material-disabled-text-color);
}

[part="drop-label-icon"] {
display: inline-block;
margin-right: 8px;
Expand Down

0 comments on commit f28c07e

Please sign in to comment.