Skip to content

Commit

Permalink
feat: show/hide keyboard on edit toggle (mozilla-mobile#20739)
Browse files Browse the repository at this point in the history
  • Loading branch information
issammani authored Jun 25, 2024
1 parent 7badcb7 commit 032be95
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import "resource://gre/modules/shared/Helpers.ios.mjs";
import { createFormLayoutFromRecord, getCurrentFormData } from "resource://gre/modules/shared/addressFormLayout.mjs";
import {
createFormLayoutFromRecord,
getCurrentFormData,
} from "resource://gre/modules/shared/addressFormLayout.mjs";

// Expose getCurrentFormData to the window object.
window.getCurrentFormData = getCurrentFormData;
/**
* Sets the theme of the webview.
* @param {Boolean} isDarkTheme - Set to true if the dark theme should be applied.
*/
const setTheme = (isDarkTheme) => {
document.body.classList.toggle("dark", isDarkTheme);
};
window.setTheme = setTheme;

/**
* Automatically resizes a textarea to fit its content.
Expand Down Expand Up @@ -73,10 +79,14 @@ const toggleEditMode = (isEditable = false) => {
textFields.forEach((element) => (element.readOnly = !isEditable));
selectElements.forEach((element) => (element.disabled = !isEditable));

textFields[0].focus();
if (isEditable) {
// Focus the first input field when entering edit mode.
// This will show the keyboard.
document.querySelector("input").focus();
} else {
// Remove focus from the input field when exiting edit mode.
// This will hide the keyboard.
document.activeElement.blur();
}
};
window.toggleEditMode = toggleEditMode;

window.getCurrentFormData = getCurrentFormData;

window.setTheme = setTheme;

0 comments on commit 032be95

Please sign in to comment.