-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: enable input into autoOpenDisabled date picker on mobile #3165
Merged
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9f9c8bc
fix: enable input into autoOpenDisabled date picker on mobile
tomivirkki da849b1
test: add tests
tomivirkki 0bb58d2
test: fix tests
tomivirkki e0b650c
fix: never enable text input on fullscreen with auto open enabled
tomivirkki d568d57
fix: enable text input on ios when dropdown is closed
tomivirkki 75cba25
test: cleanup tests
tomivirkki dbb85e5
test: cleanup tests
tomivirkki f604d7e
refactor: replace tap & touchend with click
tomivirkki 50e7c2e
test: add missing tests and cleanup
tomivirkki 4e57788
test: cleanup tests
tomivirkki 7a139ac
Merge remote-tracking branch 'origin/master' into date-picker-mobile-…
tomivirkki 4fe01cd
test: add ios autoOpenDisabled tests
tomivirkki 7c3c86f
test: add a test
tomivirkki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -1,10 +1,26 @@ | ||
import { expect } from '@esm-bundle/chai'; | ||
import { aTimeout, click, fixtureSync, oneEvent, tap } from '@vaadin/testing-helpers'; | ||
import { aTimeout, click, fixtureSync, makeSoloTouchEvent, oneEvent, tap } from '@vaadin/testing-helpers'; | ||
import { sendKeys } from '@web/test-runner-commands'; | ||
import sinon from 'sinon'; | ||
import '../src/vaadin-date-picker.js'; | ||
import * as settings from '@polymer/polymer/lib/utils/settings.js'; | ||
import { close, getOverlayContent, monthsEqual, open } from './common.js'; | ||
|
||
settings.setCancelSyntheticClickEvents(false); | ||
|
||
async function touchTap(target) { | ||
const start = makeSoloTouchEvent('touchstart', null, target); | ||
const end = makeSoloTouchEvent('touchend', null, target); | ||
if (!start.defaultPrevented && !end.defaultPrevented) { | ||
target.click(); | ||
target.focus(); | ||
} | ||
} | ||
|
||
function isFocused(target) { | ||
return target.getRootNode().activeElement === target; | ||
} | ||
|
||
describe('basic features', () => { | ||
let datepicker, input, toggleButton; | ||
|
||
|
@@ -96,14 +112,21 @@ describe('basic features', () => { | |
await oneEvent(datepicker.$.overlay, 'vaadin-overlay-open'); | ||
}); | ||
|
||
it('should not open on input tap when autoOpenDisabled is true and not on mobile', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test was moved inside "auto open disabled" |
||
datepicker.autoOpenDisabled = true; | ||
tap(input); | ||
if (!datepicker._noInput) { | ||
expect(datepicker.opened).not.to.be.true; | ||
} else { | ||
expect(datepicker.opened).to.be.true; | ||
} | ||
it('should focus the input on touch tap', () => { | ||
touchTap(input); | ||
expect(isFocused(input)).to.be.true; | ||
}); | ||
|
||
it('should not focus the input on touch tap on fullscreen', () => { | ||
datepicker._fullscreen = true; | ||
touchTap(input); | ||
expect(isFocused(input)).to.be.false; | ||
}); | ||
|
||
it('should blur the input on fullscreen', () => { | ||
datepicker._fullscreen = true; | ||
datepicker.focus(); | ||
expect(isFocused(input)).to.be.false; | ||
}); | ||
|
||
it('should pass the placeholder attribute to the input tag', () => { | ||
|
@@ -188,12 +211,6 @@ describe('basic features', () => { | |
await oneEvent(datepicker.$.overlay, 'vaadin-overlay-open'); | ||
}); | ||
|
||
it('should open by tapping the calendar icon even if autoOpenDisabled is true', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test was moved inside "auto open disabled" |
||
window.autoOpenDisabled = true; | ||
tap(toggleButton); | ||
await oneEvent(datepicker.$.overlay, 'vaadin-overlay-open'); | ||
}); | ||
|
||
it('should scroll to a date on open', async () => { | ||
const overlayContent = getOverlayContent(datepicker); | ||
// We must scroll to a date on every open because at least IE11 seems to reset | ||
|
@@ -504,7 +521,7 @@ describe('inside flexbox', () => { | |
}); | ||
}); | ||
|
||
describe('clear-button-visible', () => { | ||
describe('clear button', () => { | ||
let datepicker, clearButton; | ||
|
||
beforeEach(() => { | ||
|
@@ -516,17 +533,16 @@ describe('clear-button-visible', () => { | |
expect(datepicker).to.have.property('clearButtonVisible', true); | ||
}); | ||
|
||
it('should clear the value', () => { | ||
it('should clear the value on click', () => { | ||
datepicker.value = '2000-02-01'; | ||
click(clearButton); | ||
expect(datepicker.value).to.equal(''); | ||
}); | ||
|
||
it('should not prevent touchend event on clear button', () => { | ||
it('should clear the value on touch tap', () => { | ||
datepicker.value = '2000-02-01'; | ||
const e = new CustomEvent('touchend', { cancelable: true }); | ||
clearButton.dispatchEvent(e); | ||
expect(e.defaultPrevented).to.be.false; | ||
touchTap(clearButton); | ||
expect(datepicker.value).to.equal(''); | ||
}); | ||
|
||
it('should validate on clear', () => { | ||
|
@@ -576,3 +592,100 @@ describe('initial value attribute', () => { | |
expect(input.value).to.equal('1/1/2000'); | ||
}); | ||
}); | ||
|
||
describe('auto open disabled', () => { | ||
let datepicker, input, toggleButton; | ||
|
||
beforeEach(() => { | ||
datepicker = fixtureSync('<vaadin-date-picker value="2000-01-01"></vaadin-date-picker>'); | ||
input = datepicker.inputElement; | ||
toggleButton = datepicker.shadowRoot.querySelector('[part="toggle-button"]'); | ||
datepicker.autoOpenDisabled = true; | ||
}); | ||
|
||
it('should focus the input on touch tap', () => { | ||
touchTap(input); | ||
expect(isFocused(input)).to.be.true; | ||
}); | ||
|
||
it('should not blur the input on open', async () => { | ||
touchTap(input); | ||
await open(datepicker); | ||
expect(isFocused(input)).to.be.true; | ||
}); | ||
|
||
it('should blur the input on fullscreen open', async () => { | ||
datepicker._fullscreen = true; | ||
touchTap(input); | ||
await open(datepicker); | ||
expect(isFocused(input)).to.be.false; | ||
}); | ||
|
||
it('should not open on input tap when autoOpenDisabled is true and not on mobile', () => { | ||
tap(input); | ||
expect(datepicker.opened).not.to.be.true; | ||
}); | ||
|
||
it('should open by tapping the calendar icon even if autoOpenDisabled is true', async () => { | ||
tap(toggleButton); | ||
await oneEvent(datepicker.$.overlay, 'vaadin-overlay-open'); | ||
}); | ||
}); | ||
|
||
describe('ios', () => { | ||
let datepicker, input; | ||
|
||
beforeEach(() => { | ||
datepicker = fixtureSync('<vaadin-date-picker value="2000-01-01"></vaadin-date-picker>'); | ||
input = datepicker.inputElement; | ||
datepicker._ios = true; | ||
}); | ||
|
||
it('should focus the input when closed', () => { | ||
vursen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
datepicker.focus(); | ||
expect(isFocused(input)).to.be.true; | ||
}); | ||
|
||
it('should blur the input when opened', async () => { | ||
datepicker.focus(); | ||
await open(datepicker); | ||
expect(isFocused(input)).to.be.false; | ||
}); | ||
|
||
describe('auto open disabled', () => { | ||
let toggleButton; | ||
|
||
beforeEach(() => { | ||
datepicker.autoOpenDisabled = true; | ||
toggleButton = datepicker.shadowRoot.querySelector('[part="toggle-button"]'); | ||
}); | ||
|
||
it('should focus the input on touch tap', () => { | ||
touchTap(input); | ||
expect(isFocused(input)).to.be.true; | ||
}); | ||
|
||
it('should blur the input on open', async () => { | ||
touchTap(input); | ||
await open(datepicker); | ||
expect(isFocused(input)).to.be.false; | ||
}); | ||
|
||
it('should blur the input on fullscreen open', async () => { | ||
datepicker._fullscreen = true; | ||
touchTap(input); | ||
await open(datepicker); | ||
expect(isFocused(input)).to.be.false; | ||
}); | ||
|
||
it('should not open on input tap when autoOpenDisabled is true and not on mobile', () => { | ||
vursen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
tap(input); | ||
expect(datepicker.opened).not.to.be.true; | ||
}); | ||
|
||
it('should open by tapping the calendar icon even if autoOpenDisabled is true', async () => { | ||
tap(toggleButton); | ||
await oneEvent(datepicker.$.overlay, 'vaadin-overlay-open'); | ||
}); | ||
}); | ||
}); |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Canceling the "touchend" events seems not to be relevant anymore. It was originally added 6 years ago and was probably related to preventing ghost clicks.