Skip to content

Commit 68c3e60

Browse files
balzssclaude
andcommitted
fix(ui-color-picker): fix mixer button alignment and visual jump
Fixed two issues with the ColorPicker mixer button: 1. Alignment calculation returning 0 due to timing - measurement now happens after CSS-in-JS styles are applied using requestAnimationFrame 2. Visual jump on load - button now starts bottom-aligned and switches to top-aligned after calculation completes, minimizing the jump 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 66f2b18 commit 68c3e60

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

packages/ui-color-picker/src/ColorPicker/index.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,13 @@ class ColorPicker extends Component<ColorPickerProps, ColorPickerState> {
129129

130130
handleInputContainerRef = (el: Element | null) => {
131131
this.inputContainerRef = el
132-
this.setLabelHeight()
132+
133+
if (el) {
134+
// Defer measurement until after layout is complete and CSS-in-JS styles are applied
135+
requestAnimationFrame(() => {
136+
this.setLabelHeight()
137+
})
138+
}
133139
}
134140

135141
popoverContentRef: HTMLDivElement | null = null
@@ -488,15 +494,16 @@ class ColorPicker extends Component<ColorPickerProps, ColorPickerState> {
488494
}
489495
isShowingContent={this.state.openColorPicker}
490496
onShowContent={() => {
491-
this.setState({ openColorPicker: true, mixedColor: this.state.hexCode })
492-
}}
493-
onHideContent={() => {
494497
this.setState({
495-
openColorPicker: false,
498+
openColorPicker: true,
499+
mixedColor: this.state.hexCode,
496500
calculatedPopoverMaxHeight: undefined,
497501
isHeightCalculated: false
498502
})
499503
}}
504+
onHideContent={() => {
505+
this.setState({ openColorPicker: false })
506+
}}
500507
on="click"
501508
screenReaderLabel={this.props.popoverScreenReaderLabel}
502509
shouldContainFocus
@@ -714,7 +721,10 @@ class ColorPicker extends Component<ColorPickerProps, ColorPickerState> {
714721
{!this.isSimple && (
715722
<div
716723
css={this.props.styles?.colorMixerButtonContainer}
717-
style={{ paddingTop: this.state.labelHeight }}
724+
style={{
725+
alignSelf: this.state.labelHeight > 0 ? 'flex-start' : 'flex-end',
726+
paddingTop: this.state.labelHeight
727+
}}
718728
>
719729
<div css={this.props.styles?.colorMixerButtonWrapper}>
720730
{this.renderPopover()}

packages/ui-color-picker/src/ColorPicker/styles.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,14 @@ const generateStyle = (
122122
},
123123
colorMixerButtonContainer: {
124124
label: 'colorPicker__colorMixerButtonContainer',
125-
alignSelf: 'flex-start',
126125
marginInlineStart: componentTheme.colorMixerButtonContainerLeftMargin
127126
},
128127
popoverContentContainer: {
129128
label: 'colorPicker__popoverContentContainer',
130129
maxHeight: calculatedPopoverMaxHeight || popoverMaxHeight || '100vh',
131-
overflow: 'auto',
130+
overflowY: 'auto',
131+
overflowX: 'hidden',
132+
scrollbarGutter: 'stable',
132133
display: 'flex',
133134
flexDirection: 'column',
134135
opacity: state.isHeightCalculated ? 1 : 0,

0 commit comments

Comments
 (0)