blockly > Field > repositionForWindowResize
Field.repositionForWindowResize() method
A developer hook to reposition the WidgetDiv during a window resize. You need to define this hook if your field has a WidgetDiv that needs to reposition itself when the window is resized. For example, text input fields define this hook so that the input WidgetDiv can reposition itself on a window resize event. This is especially important when modal inputs have been disabled, as Android devices will fire a window resize event when the soft keyboard opens.
If you want the WidgetDiv to hide itself instead of repositioning, return false. This is the default behavior.
DropdownDivs already handle their own positioning logic, so you do not need to override this function if your field only has a DropdownDiv.
Signature:
repositionForWindowResize(): boolean;
Returns:
boolean
True if the field should be repositioned, false if the WidgetDiv should hide itself instead.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-09-18 UTC.
[null,null,["Last updated 2024-09-18 UTC."],[[["`Field.repositionForWindowResize()` is a method that allows developers to control the positioning of a field's WidgetDiv when the browser window is resized."],["This method is particularly useful for fields with text inputs or custom UI elements that need to adjust their position, especially on mobile devices when the keyboard appears."],["Returning `false` from this method will hide the WidgetDiv instead of repositioning it, which is the default behavior if the method is not overridden."],["Fields that only use a DropdownDiv for their UI do not need to implement this method, as DropdownDivs automatically handle their own positioning."]]],["The `repositionForWindowResize()` method is a developer hook for repositioning a field's WidgetDiv when the window resizes. It's necessary if a field uses a WidgetDiv that needs adjustment upon window resizing, particularly when modal inputs are disabled. Returning `true` prompts repositioning; `false` hides the WidgetDiv (default). Fields with only DropdownDivs don't require overriding this method, as they manage their own positioning. Text input fields use this hook.\n"]]