Skip to content

Commit

Permalink
Add support for 'dropdown' controls in JSDialog
Browse files Browse the repository at this point in the history
- Implemented `JSDialog.Dropdown` handler function to manage dropdown controls.
- Updated `JSDialogBuilder` to register the new dropdown handler.
- Modified color picker dropdown JSON to include `noDefaultKeyboardNavigation: true`.
- Removed redundant code handling dropdowns elsewhere.

Signed-off-by: Darshan-upadhyay1110 <darshan.upadhyay@collabora.com>
Change-Id: Idbcc5b2ac878cc71b3066b781eca062bc0b0aba8
  • Loading branch information
Darshan-upadhyay1110 committed Nov 26, 2024
1 parent 2b8bb6c commit dc930ff
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
1 change: 1 addition & 0 deletions browser/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ COOL_JS_LST =\
src/control/jsdialog/Widget.ColorPicker.ts \
src/control/jsdialog/Widget.Combobox.js \
src/control/jsdialog/Widget.Containers.ts \
src/control/jsdialog/Widget.DropDown.ts \
src/control/jsdialog/Widget.DrawingArea.js \
src/control/jsdialog/Widget.FormulabarEdit.js \
src/control/jsdialog/Widget.Frame.js \
Expand Down
1 change: 1 addition & 0 deletions browser/src/control/Control.JSDialogBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ L.Control.JSDialogBuilder = L.Control.extend({
this._controlHandlers['calendar'] = JSDialog.calendar;
this._controlHandlers['htmlcontent'] = JSDialog.htmlContent;
this._controlHandlers['colorpicker'] = JSDialog.colorPicker;
this._controlHandlers['dropdown'] = JSDialog.Dropdown;

this._controlHandlers['mainmenu'] = JSDialog.container;
this._controlHandlers['submenu'] = this._subMenuHandler;
Expand Down
11 changes: 2 additions & 9 deletions browser/src/control/jsdialog/Util.Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ JSDialog.OpenDropdown = function (id, popupParent, entries, innerCallback, popup
jsontype: 'dialog',
popupParent: popupParent,
popupAnchor: popupAnchor,
noDefaultKeyboardNavigation: false,
cancellable: true,
children: [
{
Expand All @@ -50,7 +51,6 @@ JSDialog.OpenDropdown = function (id, popupParent, entries, innerCallback, popup
return false;
};

var useListKeyboardNavigation = true;
for (var i in entries) {
var checkedValue = (entries[i].checked === undefined)
? undefined : (entries[i].uno && isChecked('.uno' + entries[i].uno));
Expand All @@ -70,7 +70,7 @@ JSDialog.OpenDropdown = function (id, popupParent, entries, innerCallback, popup
case 'colorpicker':
entry = entries[i];
// for color picker we have a "KeyboardGridNavigation" function defined separately to handle custom cases
useListKeyboardNavigation = false;
json.noDefaultKeyboardNavigation = true;
break;

case 'action':
Expand Down Expand Up @@ -152,14 +152,7 @@ JSDialog.OpenDropdown = function (id, popupParent, entries, innerCallback, popup
JSDialog.CloseDropdown(id);
};
};

L.Map.THIS.fire('jsdialog', {data: json, callback: generateCallback(entries)});
const listContainer = JSDialog.GetDropdown(id);
if(useListKeyboardNavigation && listContainer) {
// attach list keybinding for arrow-key navigation in entry list
JSDialog.KeyboardListNavigation(listContainer);
}

};

JSDialog.CloseDropdown = function (id) {
Expand Down
28 changes: 28 additions & 0 deletions browser/src/control/jsdialog/Widget.DropDown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* -*- js-indent-level: 8 -*- */
/*
* Copyright the Collabora Online contributors.
*
* SPDX-License-Identifier: MPL-2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

/*
* JSDialog.DropDown - build dropdown container with dynamic list
*/

declare var JSDialog: any;

JSDialog.Dropdown = function (
parentContainer: HTMLElement,
data: any,
builder: any,
) {
builder.build(parentContainer, data.children, data.vertical === true);

if (!data.noDefaultKeyboardNavigation)
JSDialog.KeyboardListNavigation(parentContainer);
return false;
};

0 comments on commit dc930ff

Please sign in to comment.