Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Font Setting - Added draggable slider #10126

Closed

Conversation

Shubham-Rasal
Copy link

@Shubham-Rasal Shubham-Rasal commented Feb 9, 2023

Signed-off-by: Shubham-Rasal bluequbits@gmail.com

Checklist

  • Tests written for new code (and old code if feasible)
  • Linter and other CI checks pass
  • Sign-off given on the changes (see CONTRIBUTING.md)

element-web notes: none

Type: enhancement

Fixes vector-im/element-web/issues/20168

In element/web the font slider in the user settings is not draggable. This is a natural user response to drag a slider , but here it just selects the text.

This is the before image as mentioned in the issue:

image

This is the result after the changes :

Element._.testing.room.-.Brave.2023-02-09.22-36-21.mp4

Here's what your changelog entry will look like:

✨ Features

Signed-off-by: Shubham-Rasal <bluequbits@gmail.com>
@Shubham-Rasal Shubham-Rasal requested a review from a team as a code owner February 9, 2023 16:16
@github-actions github-actions bot added the Z-Community-PR Issue is solved by a community member's PR label Feb 9, 2023
@Shubham-Rasal Shubham-Rasal marked this pull request as draft February 9, 2023 16:20
@Shubham-Rasal Shubham-Rasal changed the title feature: added dragable element Font Setting - Added draggable element Feb 9, 2023
@github-actions github-actions bot added the T-Enhancement New features, changes in functionality, performance boosts, user-facing improvements label Feb 9, 2023
@Shubham-Rasal Shubham-Rasal marked this pull request as ready for review February 9, 2023 17:16
@Shubham-Rasal Shubham-Rasal changed the title Font Setting - Added draggable element Font Setting - Added draggable slider Feb 9, 2023
Copy link
Contributor

@germain-gg germain-gg left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution. It's a good start 👍
However there's a few minor things to adjust. And as per the contributing guidelines, we'd expect tests to be able to include this change in the main line

if (!innerDot) return null;
// innerDot.style.left = `${this.state.percent}%`;
const offset = this.offset(this.props.values, this.props.values[value]);
innerDot.style.left = `calc(-1.195em + " + ${offset} + "%)`;
Copy link
Contributor

Choose a reason for hiding this comment

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

What does -1.195em relate to? How could we avoid that magic number?
If and we can't avoid it, we should add a thorough comment explaining how we got there

src/components/views/elements/Slider.tsx Outdated Show resolved Hide resolved
if (!target.parentNode) return null;
const parent = target.parentNode as HTMLElement;
if (!parent.parentNode) return null;
const slider = parent.parentNode as HTMLElement;
Copy link
Contributor

Choose a reason for hiding this comment

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

We should use the non-null operand here

Suggested change
const slider = parent.parentNode as HTMLElement;
const slider = parent.parentNode!;

src/components/views/elements/Slider.tsx Outdated Show resolved Hide resolved
Comment on lines +95 to +99
const target = e.target as HTMLElement;
if (!target.parentNode) return null;
const parent = target.parentNode as HTMLElement;
if (!parent.parentNode) return null;
const slider = parent.parentNode as HTMLElement;
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe we should rely on react refs instead of traversing the DOM.
The advantage I see is that we explicitely declare refs on the DOM element we wish to track.
With your approach, we rely on the fact that the DOM structure, and that is subject to change in the future

@@ -83,18 +89,73 @@ export default class Slider extends React.Component<IProps> {

let selection = null;

const onDrag = (e: React.DragEvent) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a lot of logic overlap on onDrag and onDragEnd could we consolidate those ?

Copy link
Author

Choose a reason for hiding this comment

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

Even I had that in my mind. Will make a separate function for common operations.

src/components/views/elements/Slider.tsx Outdated Show resolved Hide resolved
Shubham-Rasal and others added 4 commits February 10, 2023 15:24
removed comments

Co-authored-by: Germain <germain@souquet.com>
removed console.log comment

Co-authored-by: Germain <germain@souquet.com>
Co-authored-by: Germain <germain@souquet.com>
@kerryarchibald kerryarchibald removed their request for review February 27, 2023 20:35
@andybalaam
Copy link
Member

@Shubham-Rasal if this is ready for review again, please click the little ♻️ button next to @gsouquet 's name

@Shubham-Rasal
Copy link
Author

Shubham-Rasal commented Mar 8, 2023

@Shubham-Rasal if this is ready for review again, please click the little ♻️ button next to @gsouquet 's name

Sorry for the delay but I m not able figure out how I could refactor this to give the same output. Also a took a break for a while, sorry for that.

In the mean time if anyone wants to claim this issue, they are free to do so.

@andybalaam
Copy link
Member

andybalaam commented Mar 8, 2023

No problem at all @Shubham-Rasal - thank you for your work on this. I'm going to mark it as draft for now, since it's not ready at the moment.

@andybalaam andybalaam marked this pull request as draft March 8, 2023 17:12
@andybalaam andybalaam removed their request for review March 21, 2023 11:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
T-Enhancement New features, changes in functionality, performance boosts, user-facing improvements Z-Community-PR Issue is solved by a community member's PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Font slider should be draggable
3 participants