Closed Bug 1818287 Opened 2 years ago Closed 2 years ago

form associated custom elements with [disabled] do not fire events

Categories

(Core :: DOM: UI Events & Focus Handling, defect)

Firefox 110
defect

Tracking

()

RESOLVED FIXED
113 Branch
Tracking Status
firefox-esr102 --- unaffected
firefox110 --- wontfix
firefox111 --- wontfix
firefox112 --- wontfix
firefox113 --- fixed

People

(Reporter: clshortfuse, Assigned: avandolder)

References

(Blocks 1 open bug, Regression)

Details

(Keywords: regression)

Attachments

(2 files)

Steps to reproduce:

  • Create FACE Element with delegatesFocus = true
  • Attach :focus styles
  • Attach 'focus' event listener
  • Disable element
  • Focus element (mouse or JS)

Actual results:

  • Element received styles
  • document.activeElement changed to element
  • focus event is never fired

Expected results:

  • focus event should fire

Same should occur with keydown events. Chrome does fire keydown, focus, and blur. Chrome does not fire click events.

Click events on disabled elements aren't necessary for my use cases, but keydown, focus, and blur are. This is necessary to satisfy ARIA requirements of focusability of certain disabled elements (list items, menu items, etc).

https://w3c.github.io/aria-practices/#kbd_disabled_controls

If a disabled FACE can receive focus, it should fire a focus event and allow keyboard navigation.

If it a disable FACE cannot receive focus, it should not receive :focus state or be assigned to document.activeElement.

Codepen: https://codepen.io/shortfuse/pen/jOvqQGB

The Bugbug bot thinks this bug should belong to the 'Core::Disability Access APIs' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → Disability Access APIs
Product: Firefox → Core
Component: Disability Access APIs → DOM: UI Events & Focus Handling

:edgar, since you are the author of the regressor, bug 1800370, could you take a look? Also, could you set the severity field?

For more information, please visit auto_nag documentation.

Flags: needinfo?(echen)

There is a WPT related to a non-delegatesFocus element:

https://searchfox.org/mozilla-central/rev/edccfac5746704da49c1551aed8b79f57003bd68/testing/web-platform/tests/custom-elements/form-associated/form-disabled-callback.html#90-101

It checks everything I would think it should (activeElement and tabIndex), but it seems delegateFocus is borking it.

My current workaround is to detect Firefox and manually report and not focused:

/**
 * @param {Element} element
 * @return {boolean}
 */
export function isFocused(element) {
  if (!element) return false;
  if (IS_FIREFOX && element.constructor.formAssociated && element.hasAttribute('disabled')) {
    // https://bugzilla.mozilla.org/show_bug.cgi?id=1818287
    console.warn('Firefox bug 1818287: Disabled form associated custom element cannot receive focus.');
    return false;
  }
  if (document.activeElement === element) return true;
  if (!element.isConnected) return false;
  if (isInLightDOM(element)) return false; // extraneous 
  return element.matches(':focus');
}

It's an an acceptable workaround, but would much rather not have to skip items.

(In reply to clshortfuse from comment #3)

It checks everything I would think it should (activeElement and tabIndex), but it seems delegateFocus is borking it.

Yeah, a FACE Element is not a focusable area if it is disabled, but if it have a shadow root whose delegates focus is true, then it will delegate focus to the shadow tree. I think we probably should allow focus event on disabled element, the normal form control element, e.g. input, can not be a shadow host, so I think allowing focus event on disabled element should only affect FACE element.

And for keyboard event, we behave differently than other browsers on normal form control element, either, for example, if we have

<button disabled><span id=target tabindex=0>Span</span></button>
<script>
document.getElementById("target").focus();
</script>

and we focus the span element by calling focus() and then press keyboard, button stops propagate the keyboard event.
I think this is rare use case, so I am not aware there is bug filed for this. but for FACE+delegateFocus, this becomes noticeable, so we probably need to also allow keyboard event on disabled element.

Flags: needinfo?(echen)

Adam, do you have spare of time working on this?

If not, feel free to bounce it back to me.

Flags: needinfo?(avandolder)

I think I should be able to tackle this. For the tests, we want to make sure keyboard events propagate, and that delegatesFocus allows for focus events on disabled FACE right?

Flags: needinfo?(avandolder)

(In reply to Adam Vandolder [:avandolder] from comment #6)

For the tests, we want to make sure keyboard events propagate, and that delegatesFocus allows for focus events on disabled FACE right?

Exactly, thanks!

Assignee: nobody → avandolder
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true

Set release status flags based on info from the regressing bug 1800370

See Also: → 1819938

Followup bug for enabling this on all channels has been filed: https://bugzilla.mozilla.org/show_bug.cgi?id=1819938

Sorry, I'm a little late, but I'm also noticing some funkiness with focusin and focusout.

Since Firefox doesn't support [inert] yet, I'm trying to workaround if a FACE element child (slotted) gets focus. The setup is (roughly):

<x-card disabled onfocusin="{ if (this.disabledState) tabOverSelf(); } ">
  <slot inert={disabledState}>
    <button>I should not get focus if tabbed</button>
  </slot>
</x-card>

So, I wanted to workaround with xCardElement.addEventListener('focusin') but it never gets fired. I'm trying on 112.0a1 (2023-03-02) (64-bit) nightly, but it it could be PEBKAC, since I'm not sure if I'm on the right nightly. If focusin firing happens as a consequence of focus, then it should be fine.

(In reply to clshortfuse from comment #11)

Sorry, I'm a little late, but I'm also noticing some funkiness with focusin and focusout.

Since Firefox doesn't support [inert] yet, I'm trying to workaround if a FACE element child (slotted) gets focus. The setup is (roughly):

FWIW. inert support is on the way, see this intent-to-ship

<x-card disabled onfocusin="{ if (this.disabledState) tabOverSelf(); } ">
  <slot inert={disabledState}>
    <button>I should not get focus if tabbed</button>
  </slot>
</x-card>

So, I wanted to workaround with xCardElement.addEventListener('focusin') but it never gets fired. I'm trying on 112.0a1 (2023-03-02) (64-bit) nightly, but it it could be PEBKAC, since I'm not sure if I'm on the right nightly. If focusin firing happens as a consequence of focus, then it should be fine.

Keywords: leave-open
Pushed by avandolder@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/1848bf682441 Disabled form-associated custom elements with delegateFocus should receive focus and keyboard events. r=edgar
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/38965 for changes under testing/web-platform/tests
Upstream PR merged by moz-wptsync-bot

Set release status flags based on info from the regressing bug 1800370

Keywords: leave-open
Pushed by avandolder@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/a4ec639e1547 Part 2: Add tests for the propagation of focusin and focusout events through a disabled form-associated custom element. r=edgar
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/39142 for changes under testing/web-platform/tests
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 113 Branch
Upstream PR merged by moz-wptsync-bot

Thank you, guys. I can see it's working on Firefox nightly now :)

Regressions: 1865885
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: