From 1d98688be5a4a4c122998c9714025aa6ffe7c6b0 Mon Sep 17 00:00:00 2001 From: Marc Bernard <59966492+mbtools@users.noreply.github.com> Date: Tue, 6 Jul 2021 11:41:34 +0200 Subject: [PATCH] Dialogs: Set autofocus on first form element (#4853) * Dialogs: Set autofocus on first form element Improves usability. Closes #4816 * Autofocus for commit page - Works in case JS is not an option Co-authored-by: Lars Hvam --- src/ui/zcl_abapgit_gui_page_commit.clas.abap | 10 +++++-- src/ui/zcl_abapgit_html_form.clas.abap | 29 ++++++++++++++------ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/ui/zcl_abapgit_gui_page_commit.clas.abap b/src/ui/zcl_abapgit_gui_page_commit.clas.abap index 91f95aff5..49aa8d97f 100644 --- a/src/ui/zcl_abapgit_gui_page_commit.clas.abap +++ b/src/ui/zcl_abapgit_gui_page_commit.clas.abap @@ -25,7 +25,7 @@ CLASS zcl_abapgit_gui_page_commit DEFINITION CLASS-METHODS parse_commit_request IMPORTING - !ii_event TYPE REF TO zif_abapgit_gui_event + !ii_event TYPE REF TO zif_abapgit_gui_event RETURNING VALUE(rs_commit) TYPE zif_abapgit_services_git=>ty_commit_fields RAISING @@ -58,6 +58,7 @@ CLASS zcl_abapgit_gui_page_commit DEFINITION !iv_label TYPE string !iv_value TYPE string OPTIONAL !iv_max_length TYPE string OPTIONAL + !iv_autofocus TYPE abap_bool DEFAULT abap_false RETURNING VALUE(ri_html) TYPE REF TO zif_abapgit_html . METHODS get_comment_default @@ -283,7 +284,8 @@ CLASS zcl_abapgit_gui_page_commit IMPLEMENTATION. ri_html->add( render_text_input( iv_name = 'comment' iv_label = 'Comment' iv_value = lv_comment - iv_max_length = lv_s_param ) ). + iv_max_length = lv_s_param + iv_autofocus = abap_true ) ). ri_html->add( '
' ). ri_html->add( '' ). @@ -408,6 +410,10 @@ CLASS zcl_abapgit_gui_page_commit IMPLEMENTATION. lv_attrs = | maxlength="{ iv_max_length }"|. ENDIF. + IF iv_autofocus = abap_true. + lv_attrs = lv_attrs && ' autofocus'. + ENDIF. + ri_html->add( '
' ). ri_html->add( || ). ri_html->add( || ). diff --git a/src/ui/zcl_abapgit_html_form.clas.abap b/src/ui/zcl_abapgit_html_form.clas.abap index dabdcc0e4..b8a8799be 100644 --- a/src/ui/zcl_abapgit_html_form.clas.abap +++ b/src/ui/zcl_abapgit_html_form.clas.abap @@ -124,10 +124,10 @@ CLASS zcl_abapgit_html_form DEFINITION readonly TYPE string, placeholder TYPE string, required TYPE string, + autofocus TYPE string, END OF ty_attr . - DATA: - mt_fields TYPE zif_abapgit_html_form=>ty_fields. + DATA mt_fields TYPE zif_abapgit_html_form=>ty_fields . DATA: mt_commands TYPE STANDARD TABLE OF zif_abapgit_html_form=>ty_command . DATA mv_form_id TYPE string . @@ -138,7 +138,8 @@ CLASS zcl_abapgit_html_form DEFINITION !ii_html TYPE REF TO zif_abapgit_html !io_values TYPE REF TO zcl_abapgit_string_map !io_validation_log TYPE REF TO zcl_abapgit_string_map - !is_field TYPE zif_abapgit_html_form=>ty_field . + !is_field TYPE zif_abapgit_html_form=>ty_field + !iv_autofocus TYPE abap_bool . METHODS render_field_text IMPORTING !ii_html TYPE REF TO zif_abapgit_html @@ -341,6 +342,7 @@ CLASS zcl_abapgit_html_form IMPLEMENTATION. DATA ls_form_action TYPE string. DATA lv_cur_group TYPE string. DATA lv_url TYPE string. + DATA lv_autofocus TYPE abap_bool. IF mv_form_id IS NOT INITIAL. ls_form_id = | id="{ mv_form_id }"|. @@ -362,6 +364,7 @@ CLASS zcl_abapgit_html_form IMPLEMENTATION. EXIT. ENDLOOP. + lv_autofocus = abap_true. LOOP AT mt_fields ASSIGNING . AT FIRST. IF -type <> zif_abapgit_html_form=>c_field_type-field_group. @@ -390,7 +393,10 @@ CLASS zcl_abapgit_html_form IMPLEMENTATION. ii_html = ri_html io_values = io_values io_validation_log = io_validation_log - is_field = ). + is_field = + iv_autofocus = lv_autofocus ). + + lv_autofocus = abap_false. AT LAST. ri_html->add( || ). @@ -498,6 +504,10 @@ CLASS zcl_abapgit_html_form IMPLEMENTATION. ls_attr-readonly = ' readonly'. ENDIF. + IF iv_autofocus = abap_true. + ls_attr-autofocus = ' autofocus'. + ENDIF. + " Prepare item class lv_item_class = is_field-item_class. IF ls_attr-error IS NOT INITIAL. @@ -580,7 +590,8 @@ CLASS zcl_abapgit_html_form IMPLEMENTATION. lv_checked = ' checked'. ENDIF. - ii_html->add( || ). + ii_html->add( || ). ii_html->add( || ). ENDMETHOD. @@ -621,7 +632,7 @@ CLASS zcl_abapgit_html_form IMPLEMENTATION. lv_opt_id = |{ is_field-name }{ sy-tabix }|. ii_html->add( || ). + && | value="{ lv_opt_value }"{ lv_checked }{ is_attr-autofocus }>| ). ii_html->add( || ). ENDLOOP. @@ -724,7 +735,8 @@ CLASS zcl_abapgit_html_form IMPLEMENTATION. ENDIF. ii_html->add( || ). + && | value="{ is_attr-value }" { is_field-dblclick }{ is_attr-placeholder }| + && |{ is_attr-readonly }{ is_attr-autofocus }>| ). IF is_field-side_action IS NOT INITIAL. ii_html->add( '
' ). @@ -750,7 +762,8 @@ CLASS zcl_abapgit_html_form IMPLEMENTATION. lv_rows = lines( zcl_abapgit_convert=>split_string( is_attr-value ) ). " Avoid adding line-breaks inside textarea tag (except for the actual value) - lv_html = ||.