Use drag-pan default condition with onFocusOnly
This commit is contained in:
@@ -3,7 +3,9 @@
|
|||||||
*/
|
*/
|
||||||
import Collection from './Collection.js';
|
import Collection from './Collection.js';
|
||||||
import DoubleClickZoom from './interaction/DoubleClickZoom.js';
|
import DoubleClickZoom from './interaction/DoubleClickZoom.js';
|
||||||
import DragPan from './interaction/DragPan.js';
|
import DragPan, {
|
||||||
|
defaultCondition as dragPanDefaultCondition,
|
||||||
|
} from './interaction/DragPan.js';
|
||||||
import DragRotate from './interaction/DragRotate.js';
|
import DragRotate from './interaction/DragRotate.js';
|
||||||
import DragZoom from './interaction/DragZoom.js';
|
import DragZoom from './interaction/DragZoom.js';
|
||||||
import KeyboardPan from './interaction/KeyboardPan.js';
|
import KeyboardPan from './interaction/KeyboardPan.js';
|
||||||
@@ -112,7 +114,11 @@ export function defaults(opt_options) {
|
|||||||
if (dragPan) {
|
if (dragPan) {
|
||||||
interactions.push(
|
interactions.push(
|
||||||
new DragPan({
|
new DragPan({
|
||||||
condition: options.onFocusOnly ? focusWithTabindex : undefined,
|
condition: options.onFocusOnly
|
||||||
|
? function (event) {
|
||||||
|
return focusWithTabindex(event) && dragPanDefaultCondition(event);
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
kinetic: kinetic,
|
kinetic: kinetic,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ class DragPan extends PointerInteraction {
|
|||||||
* @param {import("../MapBrowserEvent.js").default} mapBrowserEvent Browser event.
|
* @param {import("../MapBrowserEvent.js").default} mapBrowserEvent Browser event.
|
||||||
* @return {boolean} Combined condition result.
|
* @return {boolean} Combined condition result.
|
||||||
*/
|
*/
|
||||||
function defaultCondition(mapBrowserEvent) {
|
export function defaultCondition(mapBrowserEvent) {
|
||||||
return noModifierKeys(mapBrowserEvent) && primaryAction(mapBrowserEvent);
|
return noModifierKeys(mapBrowserEvent) && primaryAction(mapBrowserEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import DoubleClickZoom from '../../../src/ol/interaction/DoubleClickZoom.js';
|
import DoubleClickZoom from '../../../src/ol/interaction/DoubleClickZoom.js';
|
||||||
import DragPan from '../../../src/ol/interaction/DragPan.js';
|
import DragPan, {
|
||||||
|
defaultCondition,
|
||||||
|
} from '../../../src/ol/interaction/DragPan.js';
|
||||||
import Feature from '../../../src/ol/Feature.js';
|
import Feature from '../../../src/ol/Feature.js';
|
||||||
import GeoJSON from '../../../src/ol/format/GeoJSON.js';
|
import GeoJSON from '../../../src/ol/format/GeoJSON.js';
|
||||||
import ImageLayer from '../../../src/ol/layer/Image.js';
|
import ImageLayer from '../../../src/ol/layer/Image.js';
|
||||||
@@ -743,13 +745,13 @@ describe('ol.Map', function () {
|
|||||||
const interactions = defaultInteractions(options);
|
const interactions = defaultInteractions(options);
|
||||||
expect(interactions.getLength()).to.eql(1);
|
expect(interactions.getLength()).to.eql(1);
|
||||||
expect(interactions.item(0)).to.be.a(DragPan);
|
expect(interactions.item(0)).to.be.a(DragPan);
|
||||||
expect(interactions.item(0).condition_).to.not.be(focusWithTabindex);
|
expect(interactions.item(0).condition_).to.be(defaultCondition);
|
||||||
});
|
});
|
||||||
it('uses the focus condition when onFocusOnly option is set', function () {
|
it('does not use the default condition when onFocusOnly option is set', function () {
|
||||||
options.onFocusOnly = true;
|
options.onFocusOnly = true;
|
||||||
options.dragPan = true;
|
options.dragPan = true;
|
||||||
const interactions = defaultInteractions(options);
|
const interactions = defaultInteractions(options);
|
||||||
expect(interactions.item(0).condition_).to.be(focusWithTabindex);
|
expect(interactions.item(0).condition_).to.not.be(defaultCondition);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user