Skip to content

Commit

Permalink
Fix primefaces#1879: Input focus() should not scroll unless autoFocus…
Browse files Browse the repository at this point in the history
…=true
  • Loading branch information
melloware committed Apr 22, 2022
1 parent a281c28 commit 5f1988b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions components/lib/autocomplete/AutoComplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export const AutoComplete = React.memo(React.forwardRef((props, ref) => {

const onDropdownClick = (event) => {
if (props.dropdownAutoFocus) {
DomHandler.focus(inputRef, false);
DomHandler.focus(inputRef, props.dropdownAutoFocus);
}

if (props.dropdownMode === 'blank')
Expand Down Expand Up @@ -423,7 +423,7 @@ export const AutoComplete = React.memo(React.forwardRef((props, ref) => {
}

if (props.autoFocus) {
DomHandler.focus(inputRef, false);
DomHandler.focus(inputRef, props.autoFocus);
}
});

Expand Down
2 changes: 1 addition & 1 deletion components/lib/dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ export const Dropdown = React.memo(React.forwardRef((props, ref) => {

useMountEffect(() => {
if (props.autoFocus) {
DomHandler.focus(focusInputRef, false);
DomHandler.focus(focusInputRef, props.autoFocus);
}
});

Expand Down
4 changes: 2 additions & 2 deletions components/lib/inputnumber/InputNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export const InputNumber = React.memo(React.forwardRef((props, ref) => {

const onUpButtonMouseDown = (event) => {
if (!props.disabled && !props.readOnly) {
DomHandler.focus(inputRef);
DomHandler.focus(inputRef, props.autoFocus);
repeat(event, null, 1);
event.preventDefault();
}
Expand Down Expand Up @@ -223,7 +223,7 @@ export const InputNumber = React.memo(React.forwardRef((props, ref) => {

const onDownButtonMouseDown = (event) => {
if (!props.disabled && !props.readOnly) {
DomHandler.focus(inputRef);
DomHandler.focus(inputRef, props.autoFocus);
repeat(event, null, -1);

event.preventDefault();
Expand Down
8 changes: 4 additions & 4 deletions components/lib/utils/DomHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -792,11 +792,11 @@ export default class DomHandler {
* Focus an input element.
*
* @param {MutableRefObject} inputRef the input reference
* @param {boolean} preventScroll flag to control whether to scroll to the element, true by default
* @param {boolean} autoFocus flag to control whether to scroll to the element, false by default
*/
static focus(inputRef, preventScroll) {
const flag = ObjectUtils.isEmpty(preventScroll) ? true : preventScroll;
inputRef && inputRef.current && inputRef.current.focus({ preventScroll: flag });
static focus(inputRef, autoFocus) {
const scroll = ObjectUtils.isEmpty(autoFocus) ? true : !autoFocus;
inputRef && inputRef.current && inputRef.current.focus({ preventScroll: scroll });
}

static getCursorOffset(el, prevText, nextText, currentText) {
Expand Down

0 comments on commit 5f1988b

Please sign in to comment.