Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not build list of available slots when no error #7731

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions packages/react-aria-components/src/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,12 @@ export function useSlottedContext<T>(context: Context<SlottedContextValue<T>>, s
return null;
}
if (ctx && typeof ctx === 'object' && 'slots' in ctx && ctx.slots) {
let availableSlots = new Intl.ListFormat().format(Object.keys(ctx.slots).map(p => `"${p}"`));

if (!slot && !ctx.slots[DEFAULT_SLOT]) {
throw new Error(`A slot prop is required. Valid slot names are ${availableSlots}.`);
}
let slotKey = slot || DEFAULT_SLOT;
if (!ctx.slots[slotKey]) {
// @ts-ignore
throw new Error(`Invalid slot "${slot}". Valid slot names are ${availableSlots}.`);
let availableSlots = new Intl.ListFormat().format(Object.keys(ctx.slots).map(p => `"${p}"`));
let errorMessage = slot ? `Invalid slot "${slot}".` : 'A slot prop is required.';

throw new Error(`${errorMessage} Valid slot names are ${availableSlots}.`);
}
return ctx.slots[slotKey];
}
Expand Down
Loading