Skip to content

Commit a5876d2

Browse files
authored
fix(s2): make avatar-only action button have square dimension (#8400)
* fix border radius of avatar in action button * fix button dimensions with avatar-only * add to chromatic * fix negative margin on avatar-only case * move padding logic to control utility * move avatar logic back to ActionButton
1 parent 4b1f8a9 commit a5876d2

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

packages/@react-spectrum/s2/chromatic/ActionButton.stories.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import {ActionButton, Text} from '../src';
13+
import {ActionButton, Avatar, Text} from '../src';
1414
import {Fonts, NotificationBadges, UnsafeClassName} from '../stories/ActionButton.stories';
1515
import {generatePowerset} from '@react-spectrum/story-utils';
1616
import type {Meta} from '@storybook/react';
@@ -82,4 +82,18 @@ export const IconOnly = {
8282
}
8383
};
8484

85+
export const WithAvatar = {
86+
render: Template,
87+
args: {
88+
children: <><Avatar src="https://i.imgur.com/xIe7Wlb.png" /><Text>Press me</Text></>
89+
}
90+
};
91+
92+
export const AvatarOnly = {
93+
render: Template,
94+
args: {
95+
children: <Avatar src="https://i.imgur.com/xIe7Wlb.png" />
96+
}
97+
};
98+
8599
export {Fonts, UnsafeClassName, NotificationBadges};

packages/@react-spectrum/s2/src/ActionButton.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export interface ActionButtonProps extends Omit<ButtonProps, 'className' | 'styl
6060

6161
// These styles handle both ActionButton and ToggleButton
6262
const iconOnly = ':has([slot=icon], [slot=avatar]):not(:has([data-rsp-slot=text]))';
63+
const avatarOnly = ':has([slot=avatar]):not(:has([slot=icon], [data-rsp-slot=text]))';
6364
const textOnly = ':has([data-rsp-slot=text]):not(:has([slot=icon], [slot=avatar]))';
6465
const controlStyle = control({shape: 'default', icon: true});
6566
export const btnStyles = style<ButtonRenderProps & ActionButtonStyleProps & ToggleButtonStyleProps & ActionGroupItemStyleProps & {isInGroup: boolean, isStaticColor: boolean}>({
@@ -226,6 +227,10 @@ export const btnStyles = style<ButtonRenderProps & ActionButtonStyleProps & Togg
226227
[iconOnly]: 'calc(self(minWidth)/2 + var(--iconWidth)/2)',
227228
[textOnly]: 'full'
228229
}
230+
},
231+
paddingX: {
232+
default: controlStyle.paddingX,
233+
[avatarOnly]: 0
229234
}
230235
}, getAllowedOverrides());
231236

@@ -291,7 +296,14 @@ export const ActionButton = forwardRef(function ActionButton(props: ActionButton
291296
}],
292297
[AvatarContext, {
293298
size: avatarSize[size],
294-
styles: style({marginStart: '--iconMargin', flexShrink: 0, order: 0})
299+
styles: style({
300+
marginStart: {
301+
default: '--iconMargin',
302+
':last-child': 0
303+
},
304+
flexShrink: 0,
305+
order: 0
306+
})
295307
}],
296308
[NotificationBadgeContext, {
297309
staticColor: staticColor,

0 commit comments

Comments
 (0)