Skip to content
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

feat: export focusWithKeyboard, focusWithMouse & assert #23

Merged
merged 1 commit into from
Jun 15, 2023

Conversation

dlockhart
Copy link
Member

Core needs these, so adding them here & exporting. I'll delete core's copy once it's switched over to use this since it doesn't appear to be used outside of core.

@dlockhart dlockhart requested a review from a team as a code owner June 15, 2023 13:10
export const focusWithKeyboard = async(element) => {
await sendKeys({ press: 'Escape' });
export async function focusWithKeyboard(element) {
await sendKeys({ press: 'Shift' }); // Tab moves focus, Escape causes dismissible things to close
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As hinted at with the comment, when using this in core Escape was causing our dropdowns and dialogs to dismiss themselves. Core's copy uses Tab which was also problematic since it moves focus around and was why our visual-diff copy used Escape.

Shift seems to be a safe option... we'll see though I guess.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha and if not we'll just keep expanding the comment until we find something that works

@@ -1,2 +1,3 @@
export { aTimeout, defineCE, expect, html, nextFrame, oneEvent, waitUntil } from '@open-wc/testing';
export { assert, aTimeout, defineCE, expect, html, nextFrame, oneEvent, waitUntil } from '@open-wc/testing';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding assert as an export. Core no longer uses it but guaranteed other projects do.


export const focusWithKeyboard = async(element) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does linting want the function setup versus the const setup, or just trying to match the style of the repo? Or is there an advantage of one over the other?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't linting related, it was more of a personal preference. TBH I'm not sure where or why the const setup was introduced... maybe in the old visual-diff library and it got copied a bunch of places? If someone knows more about why we'd want one vs. the other, chime in!

Copy link
Contributor

@svanherk svanherk Jun 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, I feel like we use the const style randomly throughout core, but it's not consistent. https://github.com/BrightspaceUI/core/blob/main/components/form/form-helper.js
https://github.com/BrightspaceUI/core/blob/main/helpers/gestures.js
And I just flip back and forth depending on what the file is already doing, so was mostly curious!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outside of using the one that's necessary based on their differences (this, scope, hoisting), at the top level like this I'll usually use an arrow function for one-liners and regular function for anything longer.

@dlockhart dlockhart merged commit 359a0de into main Jun 15, 2023
@dlockhart dlockhart deleted the dlockhart/export-focus branch June 15, 2023 17:40
@ghost
Copy link

ghost commented Jun 15, 2023

🎉 This PR is included in version 0.7.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@ghost ghost added the released label Jun 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants