| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360 |
- describe('settings', () => {
- describe('outsideClickDeselects', () => {
- const id = 'testContainer';
- beforeEach(function() {
- this.$container = $(`<div id="${id}"></div>`).appendTo('body');
- });
- afterEach(function() {
- if (this.$container) {
- destroy();
- this.$container.remove();
- }
- });
- it('should not deselect the currently selected cell after clicking on a scrollbar', () => {
- const hot = handsontable({
- outsideClickDeselects: false,
- minRows: 20,
- minCols: 2,
- width: 400,
- height: 100
- });
- selectCell(0, 0);
- const holderBoundingBox = hot.view.wt.wtTable.holder.getBoundingClientRect();
- const verticalScrollbarCoords = {
- x: holderBoundingBox.left + holderBoundingBox.width - 3,
- y: holderBoundingBox.top + (holderBoundingBox.height / 2)
- };
- const horizontalScrollbarCoords = {
- x: holderBoundingBox.left + (holderBoundingBox.width / 2),
- y: holderBoundingBox.top + holderBoundingBox.height - 3
- };
- $(hot.view.wt.wtTable.holder).simulate('mousedown', {
- clientX: verticalScrollbarCoords.x,
- clientY: verticalScrollbarCoords.y
- });
- expect(getSelected()).toEqual([[0, 0, 0, 0]]);
- $(hot.view.wt.wtTable.holder).simulate('mousedown', {
- clientX: horizontalScrollbarCoords.x,
- clientY: horizontalScrollbarCoords.y
- });
- expect(getSelected()).toEqual([[0, 0, 0, 0]]);
- });
- it('should not deselect currently selected cell', () => {
- handsontable({
- outsideClickDeselects: false
- });
- selectCell(0, 0);
- $('html').simulate('mousedown');
- expect(getSelected()).toEqual([[0, 0, 0, 0]]);
- });
- it('should not deselect currently selected cell (outsideClickDeselects as function)', () => {
- handsontable({
- outsideClickDeselects: () => false
- });
- selectCell(0, 0);
- $('html').simulate('mousedown');
- expect(getSelected()).toEqual([[0, 0, 0, 0]]);
- });
- it('should deselect currently selected cell', () => {
- handsontable({
- outsideClickDeselects: true
- });
- selectCell(0, 0);
- $('html').simulate('mousedown');
- expect(getSelected()).toBeUndefined();
- });
- it('should deselect currently selected cell (outsideClickDeselects as function)', () => {
- handsontable({
- outsideClickDeselects: () => true
- });
- selectCell(0, 0);
- $('html').simulate('mousedown');
- expect(getSelected()).toBeUndefined();
- });
- it('should allow to focus on external input when outsideClickDeselects is set as true', async() => {
- const textarea = $('<input type="text">').prependTo($('body'));
- handsontable({
- outsideClickDeselects: true
- });
- selectCell(0, 0);
- // It is necessary to fire event simulation in the next event loop cycle due to the autofocus editable element in setImmediate function.
- await sleep(0);
- textarea.simulate('mousedown');
- textarea.focus();
- expect(document.activeElement).toBe(textarea[0]);
- await sleep(50);
- expect(document.activeElement).toBe(textarea[0]);
- textarea.remove();
- });
- it('should allow to focus on external input when outsideClickDeselects is set as true (outsideClickDeselects as function)', async() => {
- const textarea = $('<input type="text">').prependTo($('body'));
- handsontable({
- outsideClickDeselects: () => true
- });
- selectCell(0, 0);
- await sleep(0);
- textarea.simulate('mousedown');
- textarea.focus();
- expect(document.activeElement).toBe(textarea[0]);
- await sleep(50);
- expect(document.activeElement).toBe(textarea[0]);
- textarea.remove();
- });
- it('should allow to focus on external input when outsideClickDeselects is set as false', async() => {
- const textarea = $('<input type="text">').prependTo($('body'));
- handsontable({
- outsideClickDeselects: false
- });
- selectCell(0, 0);
- await sleep(0);
- textarea.simulate('mousedown');
- textarea.focus();
- expect(document.activeElement).toBe(textarea[0]);
- await sleep(50);
- expect(document.activeElement).toBe(textarea[0]);
- textarea.remove();
- });
- it('should allow to focus on external input when outsideClickDeselects is set as false (outsideClickDeselects as function)', async() => {
- const textarea = $('<input type="text">').prependTo($('body'));
- handsontable({
- outsideClickDeselects: () => false
- });
- selectCell(0, 0);
- await sleep(0);
- textarea.simulate('mousedown');
- textarea.focus();
- expect(document.activeElement).toBe(textarea[0]);
- await sleep(50);
- expect(document.activeElement).toBe(textarea[0]);
- textarea.remove();
- });
- it('should allow to type in external input while holding current selection information', async() => {
- const textarea = $('<textarea></textarea>').prependTo($('body'));
- let keyPressed;
- handsontable({
- outsideClickDeselects: false
- });
- selectCell(0, 0);
- textarea.focus();
- textarea.simulate('mousedown');
- textarea.simulate('mouseup');
- textarea.on('keydown', (event) => {
- keyPressed = event.keyCode;
- });
- const LETTER_A_KEY = 97;
- $(document.activeElement).simulate('keydown', {
- keyCode: LETTER_A_KEY
- });
- // textarea should receive the event and be an active element
- expect(keyPressed).toEqual(LETTER_A_KEY);
- expect(document.activeElement).toBe(textarea[0]);
- // should preserve selection, close editor and save changes
- expect(getSelected()).toEqual([[0, 0, 0, 0]]);
- expect(getDataAtCell(0, 0)).toBeNull();
- await sleep(50);
- $(document.activeElement).simulate('keydown', {
- keyCode: LETTER_A_KEY
- });
- expect(getSelected()).toEqual([[0, 0, 0, 0]]);
- expect(getDataAtCell(0, 0)).toBeNull();
- textarea.remove();
- });
- it('should allow to type in external input while holding current selection information (outsideClickDeselects as function)', async() => {
- const textarea = $('<textarea></textarea>').prependTo($('body'));
- let keyPressed;
- handsontable({
- outsideClickDeselects: () => false
- });
- selectCell(0, 0);
- textarea.focus();
- textarea.simulate('mousedown');
- textarea.simulate('mouseup');
- textarea.on('keydown', (event) => {
- keyPressed = event.keyCode;
- });
- const LETTER_A_KEY = 97;
- $(document.activeElement).simulate('keydown', {
- keyCode: LETTER_A_KEY
- });
- // textarea should receive the event and be an active element
- expect(keyPressed).toEqual(LETTER_A_KEY);
- expect(document.activeElement).toBe(textarea[0]);
- // should preserve selection, close editor and save changes
- expect(getSelected()).toEqual([[0, 0, 0, 0]]);
- expect(getDataAtCell(0, 0)).toBeNull();
- await sleep(50);
- $(document.activeElement).simulate('keydown', {
- keyCode: LETTER_A_KEY
- });
- expect(getSelected()).toEqual([[0, 0, 0, 0]]);
- expect(getDataAtCell(0, 0)).toBeNull();
- textarea.remove();
- });
- xit('should allow to type in external input after opening cell editor', async() => {
- const textarea = $('<textarea></textarea>').prependTo($('body'));
- let keyPressed;
- handsontable({
- outsideClickDeselects: false
- });
- selectCell(0, 0);
- keyDown('enter');
- document.activeElement.value = 'Foo';
- textarea.focus();
- textarea.simulate('mousedown');
- textarea.simulate('mouseup');
- textarea.on('keydown', (event) => {
- keyPressed = event.keyCode;
- });
- const LETTER_A_KEY = 97;
- $(document.activeElement).simulate('keydown', {
- keyCode: LETTER_A_KEY
- });
- // textarea should receive the event and be an active element
- expect(keyPressed).toEqual(LETTER_A_KEY);
- expect(document.activeElement).toBe(textarea[0]);
- // should preserve selection, close editor and save changes
- expect(getSelected()).toEqual([[0, 0, 0, 0]]);
- expect(getDataAtCell(0, 0)).toEqual('Foo');
- await sleep(50);
- $(document.activeElement).simulate('keydown', {
- keyCode: LETTER_A_KEY
- });
- expect(getSelected()).toEqual([[0, 0, 0, 0]]);
- expect(getDataAtCell(0, 0)).toEqual('Foo');
- textarea.remove();
- });
- it('should allow to type in external input after opening cell editor (outsideClickDeselects as function)', async() => {
- const textarea = $('<textarea></textarea>').prependTo($('body'));
- let keyPressed;
- handsontable({
- outsideClickDeselects: () => false
- });
- selectCell(0, 0);
- keyDown('enter');
- document.activeElement.value = 'Foo';
- textarea.focus();
- textarea.simulate('mousedown');
- textarea.simulate('mouseup');
- textarea.on('keydown', (event) => {
- keyPressed = event.keyCode;
- });
- const LETTER_A_KEY = 97;
- $(document.activeElement).simulate('keydown', {
- keyCode: LETTER_A_KEY
- });
- // textarea should receive the event and be an active element
- expect(keyPressed).toEqual(LETTER_A_KEY);
- expect(document.activeElement).toBe(textarea[0]);
- // should preserve selection, close editor and save changes
- expect(getSelected()).toEqual([[0, 0, 0, 0]]);
- expect(getDataAtCell(0, 0)).toEqual('Foo');
- await sleep(50);
- $(document.activeElement).simulate('keydown', {
- keyCode: LETTER_A_KEY
- });
- expect(getSelected()).toEqual([[0, 0, 0, 0]]);
- expect(getDataAtCell(0, 0)).toEqual('Foo');
- textarea.remove();
- });
- });
- });
|