Skip to content

Commit

Permalink
Add option to not focus on widgets when created
Browse files Browse the repository at this point in the history
Allow widget definitions to include a "focusOnCreate" flag which tells the
widget whether or not to grab focus immediately after being created. This flag
defaults to true, which is the same as the previous behavior.

Closes #6
  • Loading branch information
Dylan Nugent authored and chiaoyu-addepar committed Aug 21, 2024
1 parent 3926f8c commit 3d90b3f
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions plugins/widget/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@
*
* * inserting widget element into editor,
* * marking widget instance as ready (see {@link CKEDITOR.plugins.widget#event-ready}),
* * focusing widget instance.
* * focusing widget instance if focusOnCreate is set (default)
*
* This method is used by the default widget's command and is called
* after widget's dialog (if set) is closed. It may also be used in a
Expand Down Expand Up @@ -465,7 +465,9 @@
// Fire postponed #ready event.
widget.ready = true;
widget.fire( 'ready' );
widget.focus();
if ( widget.focusOnCreate ) {
widget.focus();
}
}
},

Expand Down Expand Up @@ -978,6 +980,11 @@

draggable: widgetDef.draggable !== false,

/**
* Whether a widget should automatically be focused when it is created.
*/
focusOnCreate: widgetDef.focusOnCreate !== false,

// WAAARNING: Overwrite widgetDef's priv object, because otherwise violent unicorn's gonna visit you.
_: {
downcastFn: ( widgetDef.downcast && typeof widgetDef.downcast == 'string' ) ?
Expand Down Expand Up @@ -4811,6 +4818,13 @@
* @property {Boolean} draggable
*/

/**
* Whether widget should be focused on creation. Defaults to `true`.
* If set to `false` the widget won't have focus immediately after creation.
*
* @property {Boolean} focusOnCreate
*/

/**
* Names of element(s) (separated by spaces) for which the {@link CKEDITOR.filter} should allow classes
* defined in the widget styles. For example, if your widget is upcasted from a simple `<div>`
Expand Down

0 comments on commit 3d90b3f

Please sign in to comment.