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

removing material from checkbox #1255

Merged
merged 27 commits into from Sep 23, 2022
Merged

Conversation

Jialecl
Copy link
Collaborator

@Jialecl Jialecl commented Sep 1, 2022

No description provided.

@Jialecl
Copy link
Collaborator Author

Jialecl commented Sep 1, 2022

The visual changes are caused by a bug present in the previous version of the checkbox.
To colour the check a coloured span appears behind the check which is cut from an SVG.
When the checkbox is disabled and checked the white span can be seen through and affect the colour of the checkbox.

@raquelarrojo raquelarrojo removed their assignment Sep 2, 2022
@Jialecl Jialecl linked an issue Sep 2, 2022 that may be closed by this pull request
Copy link
Collaborator

@GomezIvann GomezIvann left a comment

Choose a reason for hiding this comment

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

Summary of things I saw along the way

  1. Disabled components should not gain the focus:

image

  1. The space between label and checkbox should mark as selected the checkbox when clickable. The cursor changes correctly to pointer, but when clicked, doesn't change checkbox's state.

Sin título

  1. I think we can take advantage of this refactor and add some more jests tests. For example:
    • "Checkbox renders with correct text" is no longer necessary since we have visual tests.
    • Check keyboard accessibility.
    • Check disabled state (and avoid bugs such as point 1).
    • Check correct values for aria attributes and role.
    • Check that the value sent in onSubmit event is correct.
    • (Any more tests you can think of)

lib/src/checkbox/Checkbox.tsx Outdated Show resolved Hide resolved
lib/src/checkbox/Checkbox.tsx Outdated Show resolved Hide resolved
lib/src/checkbox/Checkbox.tsx Outdated Show resolved Hide resolved
lib/src/checkbox/Checkbox.tsx Outdated Show resolved Hide resolved
lib/src/checkbox/Checkbox.tsx Outdated Show resolved Hide resolved
lib/src/checkbox/Checkbox.tsx Outdated Show resolved Hide resolved
lib/src/checkbox/Checkbox.tsx Outdated Show resolved Hide resolved
lib/src/checkbox/Checkbox.tsx Show resolved Hide resolved
lib/src/checkbox/Checkbox.tsx Outdated Show resolved Hide resolved
@GomezIvann GomezIvann self-assigned this Sep 5, 2022
Copy link
Collaborator

@GomezIvann GomezIvann left a comment

Choose a reason for hiding this comment

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

More comments regarding the component:

  1. The gap between the label and the checkbox doesn't change the state (hover and active) of the checkbox input.
  2. Doble click on the label selects the text.

lib/src/checkbox/Checkbox.tsx Outdated Show resolved Hide resolved
lib/src/checkbox/Checkbox.tsx Outdated Show resolved Hide resolved
lib/src/checkbox/Checkbox.tsx Outdated Show resolved Hide resolved
lib/src/checkbox/Checkbox.tsx Outdated Show resolved Hide resolved
lib/src/checkbox/Checkbox.tsx Outdated Show resolved Hide resolved
lib/src/checkbox/Checkbox.tsx Outdated Show resolved Hide resolved
lib/src/checkbox/Checkbox.tsx Outdated Show resolved Hide resolved
lib/src/checkbox/Checkbox.tsx Outdated Show resolved Hide resolved
lib/src/checkbox/Checkbox.tsx Outdated Show resolved Hide resolved
Copy link
Collaborator

@GomezIvann GomezIvann left a comment

Choose a reason for hiding this comment

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

We missed some functionality:

  • With the current implementation, our label checks the checkbox input but doesn't give it the focus. We must implement that, which is how it would work if we had to use the native checkbox input with a label and htmlFor property.
    • Add onClick event to the label and give the focus to the checkbox (ref.current.focus();)
  • Then, we must guarantee that the container, which has the "change value" functionality, doesn't steal the focus from the checkbox. This can be achieved by adding an onMouseDown to the main container with event.preventDefault().
  • And finally, we need to give the focus to the checkbox when he clicks in the gap. This should be as simple as adding ref.current.focus(); to the change value handler.
  • With the previous three points, the handleLabelDblClick handler should not be necessary.
  • Optionally, if you want to avoid unnecessary calls to the focus() method, you can check if the checkbox already has the focus, like this: document.activeElement !== ref?.current. This should be a problem but may be more precise.

lib/src/checkbox/Checkbox.tsx Outdated Show resolved Hide resolved
lib/src/checkbox/Checkbox.tsx Outdated Show resolved Hide resolved
lib/src/checkbox/Checkbox.tsx Outdated Show resolved Hide resolved
lib/src/checkbox/Checkbox.tsx Outdated Show resolved Hide resolved
@Jialecl
Copy link
Collaborator Author

Jialecl commented Sep 21, 2022

  • Then, we must guarantee that the container, which has the "change value" functionality, doesn't steal the focus from the checkbox. This can be achieved by adding an onMouseDown to the main container with event.preventDefault().

In regards to this I find it unnecessary, a div without tabIndex=0 is never focusable.
Also removes the functionality to select the label.

@GomezIvann
Copy link
Collaborator

GomezIvann commented Sep 22, 2022

  • Then, we must guarantee that the container, which has the "change value" functionality, doesn't steal the focus from the checkbox. This can be achieved by adding an onMouseDown to the main container with event.preventDefault().

In regards to this I find it unnecessary, a div without tabIndex=0 is never focusable. Also removes the functionality to select the label.

Agree!

Copy link
Collaborator

@GomezIvann GomezIvann left a comment

Choose a reason for hiding this comment

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

One final appointment:

  • We need to also test aria-labelledby and aria-required properties.

lib/src/checkbox/Checkbox.tsx Outdated Show resolved Hide resolved
lib/src/checkbox/Checkbox.test.js Outdated Show resolved Hide resolved
GomezIvann
GomezIvann previously approved these changes Sep 22, 2022
@GomezIvann GomezIvann merged commit 3216581 into master Sep 23, 2022
@GomezIvann GomezIvann deleted the jialecl-checkbox-withoutMaterial branch September 23, 2022 09:20
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.

Remove Material UI dependencies from Checkbox
3 participants