Skip to content

Commit df888a6

Browse files
Fix S2 Dialog, TagGroup, and LinkButton (#7081)
* Fix Dialog and TagGroup using the wrong ImageContext * Fix text slot in LinkButton * lint * Fix when a card collection has no previews --------- Co-authored-by: Rob Snow <[email protected]>
1 parent 554fa26 commit df888a6

File tree

5 files changed

+33
-25
lines changed

5 files changed

+33
-25
lines changed

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

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,14 @@ export interface LinkButtonProps extends Omit<LinkProps, 'className' | 'style' |
6464
export const ButtonContext = createContext<ContextValue<ButtonProps, FocusableRefValue<HTMLButtonElement>>>(null);
6565
export const LinkButtonContext = createContext<ContextValue<ButtonProps, FocusableRefValue<HTMLAnchorElement>>>(null);
6666

67+
const iconOnly = ':has([slot=icon]):not(:has([data-rsp-slot=text]))';
6768
const button = style<ButtonRenderProps & ButtonStyleProps>({
6869
...focusRing(),
6970
position: 'relative',
7071
display: 'flex',
7172
alignItems: {
7273
default: 'baseline',
73-
':has([slot=icon]):not(:has([data-rsp-slot=text]))': 'center'
74+
[iconOnly]: 'center'
7475
},
7576
justifyContent: 'center',
7677
textAlign: 'start',
@@ -80,19 +81,19 @@ const button = style<ButtonRenderProps & ButtonStyleProps>({
8081
userSelect: 'none',
8182
minHeight: 'control',
8283
minWidth: {
83-
':has([slot=icon]):not(:has([data-rsp-slot=text]))': 'control'
84+
[iconOnly]: 'control'
8485
},
8586
borderRadius: 'pill',
8687
boxSizing: 'border-box',
8788
width: 'fit',
8889
textDecoration: 'none', // for link buttons
8990
paddingX: {
9091
default: 'pill',
91-
':has([slot=icon]):not(:has([data-rsp-slot=text]))': 0
92+
[iconOnly]: 0
9293
},
9394
paddingY: 0,
9495
aspectRatio: {
95-
':has([slot=icon]):not(:has([data-rsp-slot=text]))': 'square'
96+
[iconOnly]: 'square'
9697
},
9798
transition: 'default',
9899
borderStyle: 'solid',
@@ -110,7 +111,7 @@ const button = style<ButtonRenderProps & ButtonStyleProps>({
110111
type: 'marginTop',
111112
value: {
112113
default: fontRelative(-2),
113-
':has([slot=icon]):not(:has([data-rsp-slot=text]))': 0
114+
[iconOnly]: 0
114115
}
115116
},
116117
borderColor: {
@@ -331,15 +332,18 @@ function Button(props: ButtonProps, ref: FocusableRef<HTMLButtonElement>) {
331332
<Provider
332333
values={[
333334
[SkeletonContext, null],
334-
[TextContext, {styles: style({
335-
paddingY: '--labelPadding',
336-
order: 1,
337-
opacity: {
338-
default: 1,
339-
isProgressVisible: 0
340-
}
335+
[TextContext, {
336+
styles: style({
337+
paddingY: '--labelPadding',
338+
order: 1,
339+
opacity: {
340+
default: 1,
341+
isProgressVisible: 0
342+
}
343+
})({isProgressVisible}),
341344
// @ts-ignore data-attributes allowed on all JSX elements, but adding to DOMProps has been problematic in the past
342-
})({isProgressVisible}), 'data-rsp-slot': 'text'}],
345+
'data-rsp-slot': 'text'
346+
}],
343347
[IconContext, {
344348
render: centerBaseline({slot: 'icon', styles: style({order: 0})}),
345349
styles: style({
@@ -406,7 +410,11 @@ function LinkButton(props: LinkButtonProps, ref: FocusableRef<HTMLAnchorElement>
406410
<Provider
407411
values={[
408412
[SkeletonContext, null],
409-
[TextContext, {styles: style({paddingY: '--labelPadding', order: 1})}],
413+
[TextContext, {
414+
styles: style({paddingY: '--labelPadding', order: 1}),
415+
// @ts-ignore data-attributes allowed on all JSX elements, but adding to DOMProps has been problematic in the past
416+
'data-rsp-slot': 'text'
417+
}],
410418
[IconContext, {
411419
render: centerBaseline({slot: 'icon', styles: style({order: 0})}),
412420
styles: style({size: fontRelative(20), marginStart: '--iconMargin', flexShrink: 0})

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212

1313
import {ContextValue, Keyboard as KeyboardAria, Header as RACHeader, Heading as RACHeading, TextContext as RACTextContext, SlotProps, Text as TextAria} from 'react-aria-components';
14-
import {createContext, forwardRef, ImgHTMLAttributes, ReactNode, useContext} from 'react';
14+
import {createContext, forwardRef, ReactNode, useContext} from 'react';
1515
import {DOMRef, DOMRefValue} from '@react-types/shared';
1616
import {StyleString} from '../style/types';
1717
import {UnsafeStyles} from './style-utils';
@@ -172,5 +172,3 @@ function Footer(props: ContentProps, ref: DOMRef) {
172172

173173
const _Footer = forwardRef(Footer);
174174
export {_Footer as Footer};
175-
176-
export const ImageContext = createContext<ContextValue<ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>>({});

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
import {PopoverProps as AriaPopoverProps, composeRenderProps, OverlayTriggerStateContext, Provider, Dialog as RACDialog, DialogProps as RACDialogProps} from 'react-aria-components';
1414
import {ButtonGroupContext} from './ButtonGroup';
1515
import {CloseButton} from './CloseButton';
16-
import {ContentContext, FooterContext, HeaderContext, HeadingContext, ImageContext} from './Content';
16+
import {ContentContext, FooterContext, HeaderContext, HeadingContext} from './Content';
1717
import {createContext, forwardRef, RefObject, useContext} from 'react';
1818
import {DOMRef} from '@react-types/shared';
19+
import {ImageContext} from './Image';
1920
// @ts-ignore
2021
import intlMessages from '../intl/*.json';
2122
import {Modal} from './Modal';
@@ -195,7 +196,7 @@ function DialogInner(props: DialogProps & DialogContextValue & {dialogRef: RefOb
195196
{/* Hero image */}
196197
<Provider
197198
values={[
198-
[ImageContext, {className: image}],
199+
[ImageContext, {styles: image}],
199200
[HeadingContext, {isHidden: true}],
200201
[HeaderContext, {isHidden: true}],
201202
[ContentContext, {isHidden: true}],

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ import {fontRelative, style} from '../style/spectrum-theme' with { type: 'macro'
3939
import {FormContext, useFormProps} from './Form';
4040
import {forwardRefType} from './types';
4141
import {IconContext} from './Icon';
42-
import {ImageContext, Text, TextContext} from './Content';
42+
import {ImageContext} from './Image';
4343
// @ts-ignore
4444
import intlMessages from '../intl/*.json';
4545
import {pressScale} from './pressScale';
46+
import {Text, TextContext} from './Content';
4647
import {useDOMRef} from '@react-spectrum/utils';
4748
import {useEffectEvent, useId, useLayoutEffect, useResizeObserver} from '@react-aria/utils';
4849
import {useLocalizedStringFormatter} from '@react-aria/i18n';
@@ -573,7 +574,7 @@ function TagWrapper({children, isDisabled, allowsRemoving, isInRealDOM}) {
573574
styles: style({order: 0})
574575
}],
575576
[ImageContext, {
576-
className: style({
577+
styles: style({
577578
size: fontRelative(20),
578579
flexShrink: 0,
579580
order: 0,

packages/@react-spectrum/s2/stories/CardView.stories.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function PhotoCard({item, layout}: {item: Item, layout: string}) {
6969
<Card id={item.id} textValue={item.description || item.alt_description}>
7070
{({size}) => (<>
7171
<CardPreview>
72-
<Image
72+
<Image
7373
src={item.urls.regular}
7474
styles={style({
7575
width: 'full',
@@ -133,7 +133,7 @@ export const Example = (args: CardViewProps<any>, {viewMode}) => {
133133
{(loadingState === 'loading' || loadingState === 'loadingMore') && (
134134
<SkeletonCollection>
135135
{() => (
136-
<PhotoCard
136+
<PhotoCard
137137
item={{
138138
id: Math.random(),
139139
user: {name: 'Devon Govett', profile_image: {small: ''}},
@@ -159,7 +159,7 @@ Example.args = {
159159

160160
export const Empty = (args: CardViewProps<any>, {viewMode}) => {
161161
return (
162-
<CardView
162+
<CardView
163163
aria-label="Assets"
164164
{...args}
165165
styles={cardViewStyles({viewMode})}
@@ -210,7 +210,7 @@ export const CollectionCards = (args: CardViewProps<any>, {viewMode}) => {
210210
`https://api.unsplash.com/topics?page=${page}&per_page=30&client_id=AJuU-FPh11hn7RuumUllp4ppT8kgiLS7LtOHp_sp4nc`,
211211
{signal}
212212
);
213-
let items = await res.json();
213+
let items = (await res.json()).filter((topic: Topic) => !!topic.preview_photos);
214214
return {items, cursor: items.length ? page + 1 : null};
215215
}
216216
});

0 commit comments

Comments
 (0)