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

Refactor and fix on scroll #41

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from

Conversation

caillou
Copy link

@caillou caillou commented Mar 12, 2021

In an effort to review this library before usage, I started to refactor parts of it. I ended up going a bit over-board with this. I hope this is ok:

  • Bugfix: once hidden, the floater was still repositioned on scroll.
  • Depenencies: Replaced the depricated node-sass with sass.
  • Simplify code by using class field delcarations.
  • ...

While some of these changes are very much opinion-based, I would still recommend fixing the onScroll bug and going to sass.

WDYT?

Copy link
Collaborator

@Jirinrin Jirinrin left a comment

Choose a reason for hiding this comment

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

Hi @caillou,

Thank you for your contribution! The floater repositioning bug was unknown to us, and a lot of the refactoring changes are ones I also would have liked to make eventually or are welcome surprises... so I have been reading this PR with a lot of joy :)

There were 2 things I felt a bit iffy about (the verbose deconstruction of the target element style and the whole isTabOrArrow self-documenting function which feels a tad bit much for just that one use), but honestly I think there is also something to be said for these changes, so I'm fine keeping them in.

There is a merge conflict which needs to be solved, and I added a couple minor naming inconsistency comments in the test file. So if you can fix those points, we can go ahead and merge this!

(By the way, I have now set my account to watch this repository, so you can expect a quicker response than two months from now on :) )

});
});
});

function getTargetAndContainer () {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think using the word create is more descriptive:

Suggested change
function getTargetAndContainer () {
function createTargetAndContainer() {

});

it('Should create the \'floater\' element when it is not present yet', () => {
it(`Should not recreate the 'floater' element when it's already present created`, () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
it(`Should not recreate the 'floater' element when it's already present created`, () => {
it(`Should not recreate the 'floater' element when it's already present`, () => {

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh I just realised this was also in the original test... oh well haha.

Comment on lines +70 to +71


Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change

@@ -88,22 +85,72 @@ describe('Floating focus', () => {
expect(floatingFocus.disableFloatingFocus).toHaveBeenCalled();
});

it('Should only reposition if a target and \'floater\' was set, when scrolling or resizing', async () => {
it('Scrolling should not reposition by default.', async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm always a bit pedantic about the name of tests with it hehe... Usually I'd actually prefer something like it('does not reposition the floater by default' (so without "should") but let's stick to the convention of the rest for the tests.

Suggested change
it('Scrolling should not reposition by default.', async () => {
it('Should not reposition the floater by default', async () => {

expect(floatingFocus.repositionElement).not.toHaveBeenCalled();
});

it('Scrolling should not reposition only when focusing.', async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
it('Scrolling should not reposition only when focusing.', async () => {
it('Should not reposition the floater when focusing but floating focus is inactive', async () => {


floatingFocus.floater = document.createElement('div');
floatingFocus.target = document.createElement('div');
it('Scrolling should reposition when focusing if floating is shown.', async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
it('Scrolling should reposition when focusing if floating is shown.', async () => {
it('Should reposition the floater when focusing and floating focus is active', async () => {



it('Scrolling should not reposition after blur.', async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
it('Scrolling should not reposition after blur.', async () => {
it('Should not reposition the floater after blur', async () => {


it('Scrolling should not reposition after click.', async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
it('Scrolling should not reposition after click.', async () => {
it('Should not reposition the floater after click', async () => {

Copy link
Contributor

@guidobouman guidobouman left a comment

Choose a reason for hiding this comment

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

Some small notes. =]

this.floater.classList.add('visible');
this.floater.classList.add('helper');
this.floater.classList.add('moving');
this.floater.classList.add('visible', 'helper', 'moving');
Copy link
Contributor

Choose a reason for hiding this comment

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

This breaks in all versions of IE.

const targetStyle = window.getComputedStyle(target);
const padding = targetStyle.outlineOffset || null;
const {
outlineOffset,
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this really make the code more readable?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants