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

feat: add option to disable modal inputs on mobile #6625

Merged
merged 1 commit into from
Nov 22, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/blockly_options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface BlocklyOptions {
maxBlocks?: number;
maxInstances?: {[blockType: string]: number};
media?: string;
modalInputs?: boolean;
move?: MoveOptions;
oneBasedIndex?: boolean;
readOnly?: boolean;
Expand Down
10 changes: 7 additions & 3 deletions core/field_input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,10 @@ export abstract class FieldInput<T extends InputTypes> extends Field<T> {
}

/**
* Show the inline free-text editor on top of the text.
* Show an editor for the field.
* Shows the inline free-text editor on top of the text by default.
* Shows a prompt editor for mobile browsers if the modalInputs option is
* enabled.
*
* @param _opt_e Optional mouse event that triggered the field to open, or
* undefined if triggered programmatically.
Expand All @@ -283,7 +286,7 @@ export abstract class FieldInput<T extends InputTypes> extends Field<T> {
protected override showEditor_(_opt_e?: Event, opt_quietInput?: boolean) {
this.workspace_ = (this.sourceBlock_ as BlockSvg).workspace;
const quietInput = opt_quietInput || false;
if (!quietInput &&
if (!quietInput && this.workspace_.options.modalInputs &&
(userAgent.MOBILE || userAgent.ANDROID || userAgent.IPAD)) {
this.showPromptEditor_();
} else {
Expand All @@ -293,7 +296,8 @@ export abstract class FieldInput<T extends InputTypes> extends Field<T> {

/**
* Create and show a text input editor that is a prompt (usually a popup).
* Mobile browsers have issues with in-line textareas (focus and keyboards).
* Mobile browsers may have issues with in-line textareas (focus and
* keyboards).
*/
private showPromptEditor_() {
dialog.prompt(
Expand Down
7 changes: 7 additions & 0 deletions core/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export class Options {
readOnly: boolean;
maxBlocks: number;
maxInstances: {[key: string]: number}|null;
modalInputs: boolean;
pathToMedia: string;
hasCategories: boolean;
moveOptions: MoveOptions;
Expand Down Expand Up @@ -155,6 +156,11 @@ export class Options {

const plugins = options['plugins'] || {};

let modalInputs = options['modalInputs'];
if (modalInputs === undefined) {
modalInputs = true;
}

this.RTL = rtl;
this.oneBasedIndex = oneBasedIndex;
this.collapse = hasCollapse;
Expand All @@ -163,6 +169,7 @@ export class Options {
this.readOnly = readOnly;
this.maxBlocks = options['maxBlocks'] || Infinity;
this.maxInstances = options['maxInstances'] ?? null;
this.modalInputs = modalInputs;
this.pathToMedia = pathToMedia;
this.hasCategories = hasCategories;
this.moveOptions = Options.parseMoveOptions_(options, hasCategories);
Expand Down
1 change: 1 addition & 0 deletions tests/mocha/field_textinput_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ suite('Text Input Fields', function() {
};
},
markFocused: function() {},
options: {},
};
field.sourceBlock_ = {
workspace: workspace,
Expand Down