-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(cdk/interactivity-checker) add config parameter to isFocusable #19594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
a193b96
to
5f0ce7e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. When you get a chance, could you please add the concrete use-case example to the commit message? Thanks!
5f0ce7e
to
b55af30
Compare
* @returns Whether the element is focusable. | ||
*/ | ||
isFocusable(element: HTMLElement): boolean { | ||
isFocusable(element: HTMLElement, includeDisabled = false, includeInvisible = false): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I generally try to avoid public APIs that use a boolean flag argument:
https://martinfowler.com/bliki/FlagArgument.html
I would prefer to make isPotentiallyFocusable
with a more descriptive name, though I'm having a hard time coming up with one. Maybe isPotentiallyFocusable
really is the best thing with just good JsDoc.
cc @devversion @crisbeto @andrewseguin @mmalerba ideas?
If we don't have any alternates, I'm good with just making isPotentiallyFocusable
public.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd need to think more about other good names, but if we can't come up with one: I'd personally be hesitant in naming this isPotentiallyFocusable
as it seems to signify an even worse API design than using a flag argument here. The use of potentially
is extremely ambiguous and it's never clear what it is actually referring to, unless someone dives into the description of the function or adds a good comment at call position.
Personally, I'd prefer option parameters here, as those avoid the ambiguity of flag arguments (which drive Martin Fowler's paper), and also avoid the ambiguity of potentially
. e.g.
checker.isFocusable(element, {ignoreDisabled: true});
To be clear: If we could find a good name, then I'd also prefer this over the option parameters (as I agree with the Fowler's post about flag arguments), but if not, then I'd consider the above as a more convenient/ and clear API than the exposure of isPotentiallyFocusable
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I asked my team for name suggestions for isPotentiallyFocusable. Someone suggested "isFocusableElementType", which seemed nice and descriptive, but overlooks the fact that certain attributes (contenteditable, tabindex) can also make a non-focusable type potentially focusable. Maybe "hasFocusableTypeOrAttributes"?
The option parameters sound like a good backup!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we actually care about all of the combinations here? ((true,true)
, (true,false)
, (false,true)
, (false,false)
) or just the (true,true)
and (false,false)
?
I actually prefer the flagbag if we care about all of the combinations, otherwise maybe:
isCurrentlyFocusable
isFocusableWhenNotDisabled
isFocusableWhenVisible
isFoucsableWhenVisibleAndNotDisabled
^-- bleh, so wordy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We care about the default (false, false), and for my use case I care about (false, true) because I want to include invisible elements but not disabled ones. I just added the includeDisabled flag to be consistent, but I don't actually need that flag, nor can I think of any cases off the top of my head where it would be needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slept on it, some fresh ideas:
hasFocusableIdentity
hasFocusableQualities
supportsFocus
supportsInteraction
isInteractive
readyToMakeAStageDebut
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find those kind of vague compared to the ones I suggested, I wouldn't know what they do just by looking at them. And I also still like the flagbag, Martin Fowler aside
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that adding "potentially" is too vague. I think using an optional object parameter containing booleans would be my preference, since it makes it more explicit from the caller code as well as making it easier to modify later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack- I think the config object with the options is the consensus (though I did prefer supportsFocus
myself).
So it has been decided!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated with the crowd favorite config object!
a64abc5
to
17d4355
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Adds config object to isFocusable so that it can optionally return true even when an element is invisible. Example use case: call isFocusable with ignoreVisibility=true to find a focusable element within a collapsed element. If isFocusable returns true, expand the collapsed element and focus the focusable element. Fixes angular#6468.
17d4355
to
883aa7f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome. LGTM!
@jelbourn Do you think this one could be merged soon? It seems like we can be fairly confident it won't break google3 since it just added an optional parameter, and I was hoping to use it for a small a11y feature. I saw it got tagged with "commit message fixup". Let me know if there's anything I can do to help clean that up! |
I marked it |
Thank you!! |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Adds config object to isFocusable so that it can optionally return true
even when an element is invisible. Example use case: call isFocusable
with ignoreVisibility=true to find a focusable element within a
collapsed element. If isFocusable returns true, expand the collapsed
element and focus the focusable element.
Fixes #6468.