Skip to content
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

Improve Select type cell editor #10673

Merged
merged 4 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changelogs/10673.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"issuesOrigin": "private",
"title": "Improved Select type cell editor",
"type": "changed",
"issueOrPR": 10673,
"breaking": false,
"framework": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
describe('keyboard navigation', () => {
const id = 'testContainer';

beforeEach(function() {
this.$container = $(`<div id="${id}"></div>`).appendTo('body');
});

afterEach(function() {
if (this.$container) {
destroy();
this.$container.remove();
}
});

describe('"Tab"', () => {
it('should select the next cell when the editor is opened', async() => {
handsontable({
data: createSpreadsheetData(3, 3),
rowHeaders: true,
colHeaders: true,
type: 'select',
});

selectCell(1, 1);
keyDownUp('enter');
keyDownUp('tab');

expect(getSelectedRange()).toEqualCellRange(['highlight: 1,2 from: 1,2 to: 1,2']);
});
});

describe('"Shift + Tab"', () => {
it('should select the previous cell when the editor is opened', async() => {
handsontable({
data: createSpreadsheetData(3, 3),
rowHeaders: true,
colHeaders: true,
type: 'select',
});

selectCell(1, 1);
keyDownUp('enter');
keyDownUp(['shift', 'tab']);

expect(getSelectedRange()).toEqualCellRange(['highlight: 1,0 from: 1,0 to: 1,0']);
});
});
});
15 changes: 12 additions & 3 deletions handsontable/src/editors/selectEditor/selectEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ export class SelectEditor extends BaseEditor {
* Initializes editor instance, DOM Element and mount hooks.
*/
init() {
this.select = this.hot.rootDocument.createElement('SELECT');
addClass(this.select, 'htSelectEditor');
this.select = this.hot.rootDocument.createElement('select');
this.select.setAttribute('data-hot-input', 'true');
this.select.style.display = 'none';

addClass(this.select, 'htSelectEditor');

this.hot.rootElement.appendChild(this.select);
this.registerHooks();
}
Expand Down Expand Up @@ -215,7 +217,7 @@ export class SelectEditor extends BaseEditor {
registerShortcuts() {
const shortcutManager = this.hot.getShortcutManager();
const editorContext = shortcutManager.getContext('editor');

const gridContext = shortcutManager.getContext('grid');
const contextConfig = {
group: SHORTCUTS_GROUP,
};
Expand All @@ -226,6 +228,13 @@ export class SelectEditor extends BaseEditor {
}

editorContext.addShortcuts([{
keys: [
['Tab'],
['Shift', 'Tab'],
],
forwardToContext: gridContext,
callback: () => {},
}, {
keys: [['ArrowUp']],
callback: () => {
const previousOptionIndex = this.select.selectedIndex - 1;
Expand Down