feat(range): add classes and expose parts to allow individual styling of dual knobs#30941
feat(range): add classes and expose parts to allow individual styling of dual knobs#30941brandyscarney wants to merge 26 commits intofeature-8.8from
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
This change is required otherwise it won't match knob when it has knob knob-a.
There was a problem hiding this comment.
I renamed the classes assigned to knob-handle from range-knob-a to range-knob-handle-a to match what they are actually applied to.
| configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => { | ||
| test.describe(title('range: customization'), () => { | ||
| test('should be customizable', async ({ page }) => { | ||
| await page.goto(`/src/components/range/test/custom`, config); |
There was a problem hiding this comment.
I removed the screenshots here in favor of checking that the styles are applied to the right element when the part is styled.
| * @part activated - Added to the knob-handle, knob, and pin when the knob is activated (has the `ion-activated` class). Only one set has this part at a time when `dualKnobs` is `true`. | ||
| * @part focused - Added to the knob-handle, knob, and pin that currently has focus. Only one set has this part at a time when `dualKnobs` is `true`. | ||
| * @part hover - Added to the knob-handle, knob, and pin when the knob has hover. Only one set has this part at a time when `dualKnobs` is `true`. | ||
| * @part pressed - Added to the knob-handle, knob, and pin that is currently being pressed to drag. Only one set has this part at a time when `dualKnobs` is `true`. |
There was a problem hiding this comment.
In other components we add this as the part it works with like this:
* @part wheel-item active - The currently selected wheel-item.
* @part time-button active - The time picker button when the picker is open.but it seemed like a lot to add all of these:
Details
/**
* @part knob-handle - The container element that wraps the knob and handles drag interactions.
* @part knob-handle activated - The activated knob-handle. Only one set has this part at a time when `dualKnobs` is `true`.
* @part knob-handle focused - The focused knob-handle. Only one set has this part at a time when `dualKnobs` is `true`.
* @part knob-handle hover - The hovered knob-handle. Only one set has this part at a time when `dualKnobs` is `true`.
* @part knob-handle pressed - The pressed knob-handle. Only one set has this part at a time when `dualKnobs` is `true`.
*
* @part knob-handle-a - The container element for the first knob. Only available when `dualKnobs` is `true`.
* @part knob-handle-a activated - The activated knob-handle-a. Only one set has this part at a time when `dualKnobs` is `true`.
* @part knob-handle-a focused - The focused knob-handle-a. Only one set has this part at a time when `dualKnobs` is `true`.
* @part knob-handle-a hover - The hovered knob-handle-a. Only one set has this part at a time when `dualKnobs` is `true`.
* @part knob-handle-a pressed - The pressed knob-handle-a. Only one set has this part at a time when `dualKnobs` is `true`.
*
* @part knob-handle-b - The container element for the second knob. Only available when `dualKnobs` is `true`.
* @part knob-handle-b activated - The activated knob-handle-b. Only one set has this part at a time when `dualKnobs` is `true`.
* @part knob-handle-b focused - The focused knob-handle-b. Only one set has this part at a time when `dualKnobs` is `true`.
* @part knob-handle-b hover - The hovered knob-handle-b. Only one set has this part at a time when `dualKnobs` is `true`.
* @part knob-handle-b pressed - The pressed knob-handle-b. Only one set has this part at a time when `dualKnobs` is `true`.
*
* @part knob-handle-lower - The container element for the lower knob. Only available when `dualKnobs` is `true`.
* @part knob-handle-lower activated - The activated knob-handle-lower. Only one set has this part at a time when `dualKnobs` is `true`.
* @part knob-handle-lower focused - The focused knob-handle-lower. Only one set has this part at a time when `dualKnobs` is `true`.
* @part knob-handle-lower hover - The hovered knob-handle-lower. Only one set has this part at a time when `dualKnobs` is `true`.
* @part knob-handle-lower pressed - The pressed knob-handle-lower. Only one set has this part at a time when `dualKnobs` is `true`.
*
* @part knob-handle-upper - The container element for the upper knob. Only available when `dualKnobs` is `true`.
* @part knob-handle-upper activated - The activated knob-handle-upper. Only one set has this part at a time when `dualKnobs` is `true`.
* @part knob-handle-upper focused - The focused knob-handle-upper. Only one set has this part at a time when `dualKnobs` is `true`.
* @part knob-handle-upper hover - The hovered knob-handle-upper. Only one set has this part at a time when `dualKnobs` is `true`.
* @part knob-handle-upper pressed - The pressed knob-handle-upper. Only one set has this part at a time when `dualKnobs` is `true`.
*
* @part pin - The counter that appears above a knob.
* @part pin activated - The activated pin. Only one set has this part at a time when `dualKnobs` is `true`.
* @part pin focused - The focused pin. Only one set has this part at a time when `dualKnobs` is `true`.
* @part pin hover - The hovered pin. Only one set has this part at a time when `dualKnobs` is `true`.
* @part pin pressed - The pressed pin. Only one set has this part at a time when `dualKnobs` is `true`.
*
* @part pin-a - The counter that appears above the first knob. Only available when `dualKnobs` is `true`.
* @part pin-a activated - The activated pin-a. Only one set has this part at a time when `dualKnobs` is `true`.
* @part pin-a focused - The focused pin-a. Only one set has this part at a time when `dualKnobs` is `true`.
* @part pin-a hover - The hovered pin-a. Only one set has this part at a time when `dualKnobs` is `true`.
* @part pin-a pressed - The pressed pin-a. Only one set has this part at a time when `dualKnobs` is `true`.
*
* @part pin-b - The counter that appears above the second knob. Only available when `dualKnobs` is `true`.
* @part pin-b activated - The activated pin-b. Only one set has this part at a time when `dualKnobs` is `true`.
* @part pin-b focused - The focused pin-b. Only one set has this part at a time when `dualKnobs` is `true`.
* @part pin-b hover - The hovered pin-b. Only one set has this part at a time when `dualKnobs` is `true`.
* @part pin-b pressed - The pressed pin-b. Only one set has this part at a time when `dualKnobs` is `true`.
*
* @part pin-lower - The counter that appears above the lower knob. Only available when `dualKnobs` is `true`.
* @part pin-lower activated - The activated pin-lower. Only one set has this part at a time when `dualKnobs` is `true`.
* @part pin-lower focused - The focused pin-lower. Only one set has this part at a time when `dualKnobs` is `true`.
* @part pin-lower hover - The hovered pin-lower. Only one set has this part at a time when `dualKnobs` is `true`.
* @part pin-lower pressed - The pressed pin-lower. Only one set has this part at a time when `dualKnobs` is `true`.
*
* @part pin-upper - The counter that appears above the upper knob. Only available when `dualKnobs` is `true`.
* @part pin-upper activated - The activated pin-upper. Only one set has this part at a time when `dualKnobs` is `true`.
* @part pin-upper focused - The focused pin-upper. Only one set has this part at a time when `dualKnobs` is `true`.
* @part pin-upper hover - The hovered pin-upper. Only one set has this part at a time when `dualKnobs` is `true`.
* @part pin-upper pressed - The pressed pin-upper. Only one set has this part at a time when `dualKnobs` is `true`.
*
* @part knob - The visual knob element that appears on the range track.
* @part knob activated - The activated knob. Only one set has this part at a time when `dualKnobs` is `true`.
* @part knob focused - The focused knob. Only one set has this part at a time when `dualKnobs` is `true`.
* @part knob hover - The hovered knob. Only one set has this part at a time when `dualKnobs` is `true`.
* @part knob pressed - The pressed knob. Only one set has this part at a time when `dualKnobs` is `true`.
*
* @part knob-a - The visual knob element for the first knob. Only available when `dualKnobs` is `true`.
* @part knob-a activated - The activated knob-a. Only one set has this part at a time when `dualKnobs` is `true`.
* @part knob-a focused - The focused knob-a. Only one set has this part at a time when `dualKnobs` is `true`.
* @part knob-a hover - The hovered knob-a. Only one set has this part at a time when `dualKnobs` is `true`.
* @part knob-a pressed - The pressed knob-a. Only one set has this part at a time when `dualKnobs` is `true`.
*
* @part knob-b - The visual knob element for the second knob. Only available when `dualKnobs` is `true`.
* @part knob-b activated - The activated knob-b. Only one set has this part at a time when `dualKnobs` is `true`.
* @part knob-b focused - The focused knob-b. Only one set has this part at a time when `dualKnobs` is `true`.
* @part knob-b hover - The hovered knob-b. Only one set has this part at a time when `dualKnobs` is `true`.
* @part knob-b pressed - The pressed knob-b. Only one set has this part at a time when `dualKnobs` is `true`.
*
* @part knob-lower - The visual knob element for the lower knob. Only available when `dualKnobs` is `true`.
* @part knob-lower activated - The activated knob-lower. Only one set has this part at a time when `dualKnobs` is `true`.
* @part knob-lower focused - The focused knob-lower. Only one set has this part at a time when `dualKnobs` is `true`.
* @part knob-lower hover - The hovered knob-lower. Only one set has this part at a time when `dualKnobs` is `true`.
* @part knob-lower pressed - The pressed knob-lower. Only one set has this part at a time when `dualKnobs` is `true`.
*
* @part knob-upper - The visual knob element for the upper knob. Only available when `dualKnobs` is `true`.
* @part knob-upper activated - The activated knob-upper. Only one set has this part at a time when `dualKnobs` is `true`.
* @part knob-upper focused - The focused knob-upper. Only one set has this part at a time when `dualKnobs` is `true`.
* @part knob-upper hover - The hovered knob-upper. Only one set has this part at a time when `dualKnobs` is `true`.
* @part knob-upper pressed - The pressed knob-upper. Only one set has this part at a time when `dualKnobs` is `true`.
*/There was a problem hiding this comment.
I vote to not include them. Anyone who works with parts are most likely familiar with how to group them so we shouldn't need the extra docs.
| ></ion-range> | ||
|
|
||
| <!-- 2nd Custom Range: Single Knob --> | ||
| <h2>Custom Range: Single Knob</h2> |
There was a problem hiding this comment.
I've verified that I can click on the knob and then use the arrow keys to move the knob without ever dragging it. However, when I stop pressing on the knob, the value is reset to the original. I would assume that it would be changed to the value that I moved to with the arrow keys.
No issues with focusing and arrow keys, it updates the value as expected.
| ></ion-range> | ||
|
|
||
| <!-- 2nd Custom Range: Single Knob --> | ||
| <h2>Custom Range: Single Knob</h2> |
There was a problem hiding this comment.
Verified the following but it can be hard to tell between the dark primary and the default. It would be great if it can be different colors to be make it more obvious.
- Verify that the knob shows as the dark primary color when the knob is pressed and you drag the cursor down away from the range (activated)
- Verify that the knob shows as the default primary color when the knob is being dragged (pressed)
| </ion-range> | ||
|
|
||
| <!-- 3rd Custom Range: Dual Knobs with Knob Lower & Upper --> | ||
| <h2>Custom Range: Dual Knobs with Knob Lower & Upper</h2> |
There was a problem hiding this comment.
I've verified that I can click on the knob and then use the arrow keys to move the knob without ever dragging it. However, when I stop pressing on the knob, the value is reset to the original. I would assume that it would be changed to the value that I moved to with the arrow keys.
No issues with focusing and arrow keys, it updates the value as expected.
| </ion-range> | ||
|
|
||
| <!-- 3rd Custom Range: Dual Knobs with Knob Lower & Upper --> | ||
| <h2>Custom Range: Dual Knobs with Knob Lower & Upper</h2> |
There was a problem hiding this comment.
Verified the following but it can be hard to tell between the light primary and the dark primary. It would be great if it can be different colors to be make it more obvious.
- Verify that the knob shows as the light primary color when the lower knob is being dragged (pressed)
- Verify that the knob shows as the dark primary color when the upper knob is being dragged (pressed)
| </ion-range> | ||
|
|
||
| <!-- 4th Custom Range: Dual Knobs with Knob A & B --> | ||
| <h2>Custom Range: Dual Knobs with Knob A & B</h2> |
There was a problem hiding this comment.
I've verified that I can click on the knob and then use the arrow keys to move the knob without ever dragging it. However, when I stop pressing on the knob, the value is reset to the original. I would assume that it would be changed to the value that I moved to with the arrow keys.
No issues with focusing and arrow keys, it updates the value as expected.
| * @part knob-lower - The visual knob element for the lower knob. Only available when `dualKnobs` is `true`. | ||
| * @part knob-upper - The visual knob element for the upper knob. Only available when `dualKnobs` is `true`. |
There was a problem hiding this comment.
It would be beneficial to elaborate what lower and upper mean in terms of values.
| * @part knob-b - The visual knob element for the second knob. Only available when `dualKnobs` is `true`. | ||
| * @part knob-lower - The visual knob element for the lower knob. Only available when `dualKnobs` is `true`. | ||
| * @part knob-upper - The visual knob element for the upper knob. Only available when `dualKnobs` is `true`. | ||
| * @part activated - Added to the knob-handle, knob, and pin when the knob is activated (has the `ion-activated` class). Only one set has this part at a time when `dualKnobs` is `true`. |
There was a problem hiding this comment.
Do we need to point out that it has the ion-activated class? It feels like too much info.
| * @part activated - Added to the knob-handle, knob, and pin when the knob is activated (has the `ion-activated` class). Only one set has this part at a time when `dualKnobs` is `true`. | ||
| * @part focused - Added to the knob-handle, knob, and pin that currently has focus. Only one set has this part at a time when `dualKnobs` is `true`. | ||
| * @part hover - Added to the knob-handle, knob, and pin when the knob has hover. Only one set has this part at a time when `dualKnobs` is `true`. | ||
| * @part pressed - Added to the knob-handle, knob, and pin that is currently being pressed to drag. Only one set has this part at a time when `dualKnobs` is `true`. |
There was a problem hiding this comment.
I vote to not include them. Anyone who works with parts are most likely familiar with how to group them so we shouldn't need the extra docs.
| private focusFromPointer = false; | ||
| private activatedObserver?: MutationObserver; |
There was a problem hiding this comment.
Let's add short comments for what these variables are for. It'll be great to be able to look at them and immediately know their purpose instead of reading through the code. Especially since they seem like they do complex work.
| 'range-knob-max': value === max, | ||
| 'ion-activatable': true, | ||
| 'ion-focusable': true, | ||
| 'ion-focused': focused, |
There was a problem hiding this comment.
This doesn't clash with ion-focusable?
Issue number: resolves #29862
What is the current behavior?
Range exposes a single part for both knobs & pins. This makes it impossible to style the knobs/pins differently when dual knobs is enabled.
What is the new behavior?
dualKnobsis enabled:range-dual-knobsrange-pressed-awhen the knob with name A is pressedrange-pressed-bwhen the knob with name B is pressedrange-pressed-lowerwhen the lower knob is pressedrange-pressed-upperwhen the upper knob is pressedknob-handle-a- The container element for the first knob. Only available whendualKnobsistrue.knob-handle-b- The container element for the second knob. Only available whendualKnobsistrue.knob-handle-lower- The container element for the lower knob. Only available whendualKnobsistrue.knob-handle-upper- The container element for the upper knob. Only available whendualKnobsistrue.pin-a- The counter that appears above the first knob. Only available whendualKnobsistrue.pin-b- The counter that appears above the second knob. Only available whendualKnobsistrue.pin-lower- The counter that appears above the lower knob. Only available whendualKnobsistrue.pin-upper- The counter that appears above the upper knob. Only available whendualKnobsistrue.knob-a- The visual knob element for the first knob. Only available whendualKnobsistrue.knob-b- The visual knob element for the second knob. Only available whendualKnobsistrue.knob-lower- The visual knob element for the lower knob. Only available whendualKnobsistrue.knob-upper- The visual knob element for the upper knob. Only available whendualKnobsistrue.pressed- Added to the knob-handle, knob, and pin that is currently being pressed to drag. Only one set has this part at a time.focused- Added to the knob-handle, knob, and pin that currently has focus. Only one set has this part at a time.hover- Added to the knob-handle, knob, and pin when the knob has hover. Only one set has this part at a time.activated- Added to the knob-handle, knob, and pin when the knob is activated. Only one set has this part at a time.Does this introduce a breaking change?
Other information
Dev build:
8.7.17-dev.11771959013.18adabe2