-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add disabled property to grid (#3445) (#2211)
- Loading branch information
Showing
11 changed files
with
203 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<!-- | ||
@license | ||
Copyright (c) 2017 Vaadin Ltd. | ||
This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
--> | ||
|
||
<script> | ||
window.Vaadin = window.Vaadin || {}; | ||
Vaadin.Grid = Vaadin.Grid || {}; | ||
|
||
/** | ||
* @polymerMixin | ||
*/ | ||
Vaadin.Grid.DisabledMixin = superClass => class DisabledMixin extends superClass { | ||
static get properties() { | ||
return { | ||
disabled: { | ||
type: Boolean, | ||
value: false, | ||
observer: '_disabledChanged', | ||
reflectToAttribute: true | ||
} | ||
}; | ||
} | ||
|
||
/** @protected */ | ||
_disabledChanged(disabled) { | ||
if (disabled) { | ||
this.setAttribute('tabindex', '-1'); | ||
this.setAttribute('aria-disabled', 'true'); | ||
} else { | ||
this.removeAttribute('tabindex'); | ||
this.removeAttribute('aria-disabled'); | ||
} | ||
} | ||
|
||
/** | ||
* Overrides the default element `click` method in order to prevent | ||
* firing the `click` event when the element is disabled. | ||
* @protected | ||
* @override | ||
*/ | ||
click() { | ||
if (!this.disabled) { | ||
super.click(); | ||
} | ||
} | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<!doctype html> | ||
|
||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>disabled tests</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"> | ||
|
||
<script src="settings.js"></script> | ||
<script src="../../webcomponentsjs/webcomponents-lite.js"></script> | ||
<script src="../../web-component-tester/browser.js"></script> | ||
<link rel="import" href="../../test-fixture/test-fixture.html"> | ||
|
||
<link rel="import" href="helpers.html"> | ||
<link rel="import" href="../vaadin-grid.html"> | ||
</head> | ||
<body> | ||
<test-fixture id="grid"> | ||
<template> | ||
<vaadin-grid> | ||
<vaadin-grid-column path="foo"></vaadin-grid-column> | ||
<vaadin-grid-column path="bar"></vaadin-grid-column> | ||
</vaadin-grid> | ||
</template> | ||
</text-fixture> | ||
|
||
<script> | ||
describe('disabled', () => { | ||
let grid; | ||
|
||
beforeEach(() => { | ||
grid = fixture('grid'); | ||
grid.items = [ | ||
{foo: '1', bar: '1'}, | ||
{foo: '2', bar: '2'} | ||
]; | ||
flushGrid(grid); | ||
}); | ||
|
||
it('should not set the disabled property by default', () => { | ||
expect(grid.disabled).to.be.false; | ||
}); | ||
|
||
it('should reflect the disabled property to the attribute', () => { | ||
grid.disabled = true; | ||
expect(grid.hasAttribute('disabled')).to.be.true; | ||
|
||
grid.disabled = false; | ||
expect(grid.hasAttribute('disabled')).to.be.false; | ||
}); | ||
|
||
it('should set the aria-disabled attribute when disabled', () => { | ||
grid.disabled = true; | ||
expect(grid.getAttribute('aria-disabled')).to.equal('true'); | ||
|
||
grid.disabled = false; | ||
expect(grid.hasAttribute('aria-disabled')).to.be.false; | ||
}); | ||
|
||
it('should set the tabindex attribute to -1 when disabled', () => { | ||
grid.disabled = true; | ||
expect(grid.getAttribute('tabindex')).to.equal('-1'); | ||
|
||
grid.disabled = false; | ||
expect(grid.hasAttribute('tabindex')).to.be.false; | ||
}); | ||
|
||
it('should prevent firing click events when disabled', () => { | ||
const spy = sinon.spy(); | ||
grid.addEventListener('click', spy); | ||
grid.disabled = true; | ||
grid.click(); | ||
expect(spy.called).to.be.false; | ||
}); | ||
|
||
it('should set pointer-events: none when disabled', () => { | ||
grid.disabled = true; | ||
expect(getComputedStyle(grid).pointerEvents).to.equal('none'); | ||
grid.disabled = false; | ||
expect(getComputedStyle(grid).pointerEvents).not.to.equal('none'); | ||
}); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<!DOCTYPE html> | ||
|
||
<head lang="en"> | ||
<meta charset="UTF-8"> | ||
<title>disabled visual tests</title> | ||
<script src="../../../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-grid.html">`); | ||
|
||
const dir = window.location.search.replace(/.*dir=(\w+).*/, '$1') || 'ltr'; | ||
document.documentElement.setAttribute('dir', dir); | ||
</script> | ||
<script src="../../demo/grid-demo-data.js"></script> | ||
<link href="../../demo/x-data-provider.html" rel="import"> | ||
</head> | ||
|
||
<body> | ||
<style media="screen"> | ||
.capture-block { | ||
display: inline-block; | ||
width: 800px; | ||
} | ||
</style> | ||
|
||
<div class="capture-block" id="disabled"> | ||
<dom-bind> | ||
<template> | ||
<custom-style> | ||
<style> | ||
vaadin-grid { | ||
height: 250px; | ||
} | ||
</style> | ||
</custom-style> | ||
<x-array-data-provider items="{{items}}"></x-array-data-provider> | ||
<vaadin-grid items="[[items]]" size="200" disabled> | ||
<vaadin-grid-column path="name.first" header="First name"></vaadin-grid-column> | ||
<vaadin-grid-column path="name.last" header="Last name"></vaadin-grid-column> | ||
<vaadin-grid-column path="email"></vaadin-grid-column> | ||
</vaadin-grid> | ||
</template> | ||
</dom-bind> | ||
</div> | ||
</body> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+18.3 KB
test/visual/screens/vaadin-grid/disabled-material/disabled/chrome.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters