Edgewall Software
Modify

Opened 4 years ago

Last modified 8 months ago

#13235 new defect

Comment textarea doesn't get focus on loading when replying using Firefox and Edge

Reported by: Jun Omae Owned by:
Priority: normal Milestone: next-stable-1.6.x
Component: rendering Version: 1.0.19
Severity: minor Keywords:
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

We expect comment textarea gets focus when visiting https://trac.edgewall.org/demo-1.0/ticket/1?replyto=description#comment, however it doesn't work using Firefox and Edge. It works fine using Chrome.

Attachments (0)

Change History (6)

comment:1 by Jun Omae, 4 years ago

Owner: set to Jun Omae
Status: newassigned

Work around is to focus it when the given element in the hash is input element:

  • trac/templates/layout.html

    diff --git a/trac/templates/layout.html b/trac/templates/layout.html
    index 48f2d3e7b..36d786891 100644
    a b  
    5757          return false;
    5858        });
    5959        </py:if>
    60         $(".trac-autofocus").focus();
     60        var autofocus = location.hash;
     61        autofocus = autofocus ? document.getElementById(autofocus.substring(1))
     62                              : null;
     63        if (autofocus !== null) {
     64          autofocus = $(autofocus);
     65          if (!autofocus.is(':input'))
     66            autofocus = null;
     67        }
     68        if (autofocus === null)
     69          autofocus = $(".trac-autofocus");
     70        autofocus.focus();
    6171        $(".trac-target-new").attr("target", "_blank");
    6272        setTimeout(function() { $(".trac-scroll").scrollToTop() }, 1);
    6373        $(".trac-disable-on-submit").disableOnSubmit();

comment:2 by Jun Omae, 4 years ago

In 1.2-stable, comment textarea gets focus when replying. trac-autofocus is used in class attribute of comment textare after [14393] (#11835 but not described).

Backport:

  • trac/ticket/templates/ticket.html

    diff --git a/trac/ticket/templates/ticket.html b/trac/ticket/templates/ticket.html
    index 057b64a38..d27dbbda1 100644
    a b  
    205205                <a tabindex="42" href="${href.wiki('WikiFormatting')}">WikiFormatting</a>
    206206                here.
    207207              </label>
    208               <textarea id="comment" name="comment" class="wikitext trac-fullwidth trac-resizable" rows="10" cols="78">
     208              <textarea id="comment" name="comment" class="${classes('wikitext', 'trac-fullwidth', 'trac-resizable', 'trac-autofocus' if replyto else None)}" rows="10" cols="78">
    209209${comment}</textarea>
    210210            </fieldset>
    211211          </div>

comment:3 by Ryan J Ollos, 4 years ago

Confirmed reply-to autofocus works on 1.2-stable and for 1.0-stable with Chrome, but not 1.0-stable with Firefox 77. I tried both comment:1 and comment:2 patches, but they don't seem to fix the issue. Do the patches still fix the issue for you?

Last edited 4 years ago by Ryan J Ollos (previous) (diff)

comment:4 by Jun Omae, 4 years ago

I noticed comment editor has the same issue but the issue also has been fixed in 1.2-stable.

  • trac/ticket/templates/ticket.html

    diff --git a/trac/ticket/templates/ticket.html b/trac/ticket/templates/ticket.html
    index 92da3677c..56e28e861 100644
    a b  
    205205                <a tabindex="42" href="${href.wiki('WikiFormatting')}">WikiFormatting</a>
    206206                here.
    207207              </label>
    208               <textarea id="comment" name="comment" class="wikitext trac-fullwidth trac-resizable" rows="10" cols="78">
     208              <textarea id="comment" name="comment" class="${classes('wikitext', 'trac-fullwidth', 'trac-resizable', 'trac-autofocus' if replyto else None)}" rows="10" cols="78">
    209209${comment}</textarea>
    210210            </fieldset>
    211211          </div>
  • trac/ticket/templates/ticket_change.html

    diff --git a/trac/ticket/templates/ticket_change.html b/trac/ticket/templates/ticket_change.html
    index 662384b4b..db228d322 100644
    a b Arguments:  
    116116  <form py:if="show_editor" id="trac-comment-editor" method="post"
    117117        action="${href.ticket(ticket.id) + '#comment:%d' % cnum}">
    118118    <div>
    119       <textarea name="edited_comment" class="wikitext trac-fullwidth trac-resizable" rows="10" cols="78">
     119      <textarea name="edited_comment" class="wikitext trac-fullwidth trac-resizable trac-autofocus" rows="10" cols="78">
    120120${edited_comment if edited_comment is not None else change.comment}</textarea>
    121121      <input type="hidden" name="cnum_edit" value="${cnum}"/>
    122122    </div>

The patch would fix the issue on both reply and edit with Firefox in my environment but the issue on edit with Chrome is not fixed.

Hmm, I think it seems focusing by anchor (e.g. #comment, #comment:N) and trac-autofocus are conflicting. By the conflicting, textarea may not be focused.

comment:5 by Jun Omae, 4 years ago

Milestone: 1.0.20next-stable-1.4.x
Owner: Jun Omae removed
Severity: normalminor
Status: assignednew

Additional changes would make fine on both Firefox and Chrome but edit doesn't focus textarea for edit-comment on Edge. I cannot find perfect solution. Re-targeting to next-stable-1.4. That is a minor issue….

  • trac/templates/layout.html

    diff --git a/trac/templates/layout.html b/trac/templates/layout.html
    index 25ea9ff67..9f6074d1a 100644
    a b  
    5757          return false;
    5858        });
    5959        </py:if>
    60         $(".trac-autofocus").focus();
     60        var autofocus = $(".trac-autofocus");
     61        if (autofocus.length !== 0) {
     62          if (location.hash)
     63            setTimeout(function() { autofocus.focus() }, 1);
     64          else
     65            autofocus.focus();
     66        }
    6167        $(".trac-target-new").attr("target", "_blank");
    6268        setTimeout(function() { $(".trac-scroll").scrollToTop() }, 1);
    6369        $(".trac-disable-on-submit").disableOnSubmit();

comment:6 by Ryan J Ollos, 8 months ago

Milestone: next-stable-1.4.xnext-stable-1.6.x

Milestone renamed

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The ticket will remain with no owner.
The ticket will be disowned.
as The resolution will be set. Next status will be 'closed'.
The owner will be changed from (none) to anonymous. Next status will be 'assigned'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.