-
Notifications
You must be signed in to change notification settings - Fork 973
SwitchControl text now toggles checked state, and is consistently used #10470
Conversation
…ed state Partial resolution for brave#8243 since many usages do not use the built-in text but render their own text separately. A subsequent commit will address converting these usages. This also converts text from span to label for accessbility and more appropriate renderer defaults (the cursor).
} | ||
} | ||
} | ||
|
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.
Is it OK to remove them all? Was &.disabled
for example converted anywhere?
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.
@luixxiul all the removed styles that were in SettingsCheckBox were already in switchControls.less. The one that wasn't is the space between the label and the switch element. See description for question on whether this should now match all other uses of SwitchControl in the app.
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.
The one that wasn't is the space between the label and the switch element.
Why don't we re-add the space for now until we find a better way of handling the padding than we have currently, avoiding the visual regression?
My idea:
- remove padding from the toggle switch (on the very same reason we did remove the margin from browserButton: the switch as such does not require the margin/padding. It gets required only other elements appear around the switch)
- add
Xch
(0.5 - 1ch) to the label - add margin to SettingList in which the switch and the label are wrapped
That is out of scope of this PR so you would not need to address them
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.
Previously the text was rendered with a label element outside the SwitchControl
. This made it easier to have custom spacing without affecting the switchControl css, but it broke the label being able to toggle the switch. Now that the SettingsCheckbox
(and all usages of that) is passing the text to SwitchControl
for labels, the style would have to either be part of SwitchControl
or a style override from the usage location, adding to the fragmented style definition problem for the component, that will have to be resolved or integrated in a future refactor. Note that not all uses of SettingsCheckbox
have this spacing (see the Payments tab), so this spacing is very specific to a couple of places. Happy to do that if it can't be resolved now, but thought I'd try just in case it was a simple ok in order to avoid the fragmentation.
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.
That sounds good to me. Would you mind adding TODO
comment to the source code about the visual regression? I think we should not tackle the issue with this PR. I am pretty sure that normalizing SwitchControl
requires massive tasks (including adding them to about:styles
) and it blocks this PR to be merged for a while.
If, however, no visual regressions are allowed, overriding with !important
will be required.
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 took another look at it and added a prop to SettingCheckbox
that enables 'compact' styles (i.e. no gap). So by default, the gap is there. So, there should not be a visual regression anymore as long as 773dbb1 is ok
@@ -275,16 +279,15 @@ class FindBar extends React.Component { | |||
id='caseSensitivityCheckbox' | |||
checkedOn={this.props.isCaseSensitive} | |||
onClick={this.onCaseSensitivityChange} | |||
/> | |||
<label | |||
htmlFor='caseSensitivityCheckbox' |
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.
Is it OK to remove this?
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.
The label is now being rendered by the switchControl, and the findBarTestStyle style overrides have been changed to aphrodite-style findBarTextStyles css.
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.
indeed!
<label className={labelClass} | ||
data-l10n-id={this.props.dataL10nId} | ||
data-l10n-args={this.props.dataL10nArgs} | ||
htmlFor={this.props.prefKey} |
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.
ditto.
} | ||
} | ||
|
||
&.large { |
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.
ok to remove this?
@@ -36,6 +36,19 @@ | |||
} | |||
} | |||
} | |||
|
|||
&.small { |
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.
This change affects every switch controls outside of about:preferences
too. did you confirm this does not regress something?
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.
In my search, no other component currently uses the small variant apart from about:preferences
, this moves the previous style override to the shared component as the large variant already was.
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 left initial feedback comments. would you mind adding comments to removed lines on LESS files to make sure the removal is actually safe? thanks!
@petemill does the change not regress switches on about:adblock? |
and their text labels Adds 'compact' prop to SettingCheckbox. By default, the gap is there since that is the most common state. As per review of brave#10470
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 tested the PR manually and the change looks good to me. Would you mind squashing the last two commits and, if necessary, reword the commit messages?
closes brave#8243 as this ensures all remaining uses of switchControl gain the built-in label click handler. covers the case-sensitivity toggle in findbar, as well as all the switches on the preferences page.
773dbb1
to
b0460f4
Compare
@luixxiul I squashed the fixes |
@petemill thank you |
Codecov Report
@@ Coverage Diff @@
## master #10470 +/- ##
==========================================
- Coverage 54.09% 54.09% -0.01%
==========================================
Files 245 245
Lines 21223 21222 -1
Branches 3283 3283
==========================================
- Hits 11481 11480 -1
Misses 9742 9742
|
Great job on this one, @petemill! 😄 👍 |
Test Plan
Supporting text click on switchControl
The click event will now fire from the label, whether it is to the left, right, or top of the switch element.
This also converts text from
<span />
to<label />
for accessibility and more appropriate renderer defaults (the cursor) to convey that clicking the label will toggle the checked state.Usages this affects:
This is a partial resolution only for #8243 since many usages do not use the built-in switchControl label element but render their own text separately. Changing some of those usages to the switchControl label element causes some minor visual regression which may warrant some discussion. A subsequent PR will address converting these usages, which are not covered by this PR:
Ensuring SwitchControl text prop is provided across usages
This ensures all remaining uses of
SwitchControl
gain the built-in text label click handler.Covers:
I refactored a lot of the
SettingCheckbox
component as it was duplicating quite a bit of theSwitchControl
styles even though it was including the common component, which was creating style conflicts when using the text label feature ofSwitchControl
- a result of integrating the fix for #8243.I created a separate PR for this as it involves changes to multiple components which consumed
SwitchControl
in different ways. If that is too granular then I'm happy to combine these changes with #10468.I'm aware of #7321 which calls for a larger refactor of switchControl and can be a good opportunity to create a cleaner version of this component whilst analyzing the different state variations now required from the varied uses I've come across. I made sure usages of the component are more consistent, but did not attempt a clean-up of the existing version of the component because of that upcoming issue.
Submitter Checklist:
git rebase -i
to squash commits (if needed).Reviewer Checklist:
Tests