Skip to content

Conversation

@ZeroGDrive
Copy link

Summary

Fixes #283

This PR makes CSS classes work for object-fit without any extra props needed.

Problem

The objectFit prop defaulted to "cover" and was applied as an inline style. Since inline styles have higher specificity than CSS classes, users couldn't override object-fit via CSS-in-JS libraries or CSS modules.

// Before: Doesn't work - inline style overrides the class
<Image
  src={props.img.src}
  layout="fullWidth"
  class={style({ objectFit: "contain" })}
/>

Solution

Only apply the default object-fit: cover when no class or className prop is provided. This way:

Scenario Behavior
No class, no objectFit object-fit: cover (backward compatible)
With class, no objectFit No inline object-fit (CSS controls it)
Explicit objectFit prop Always applied (regardless of class)
// After: Just works!
<Image
  src={props.img.src}
  layout="fullWidth"
  class={style({ objectFit: "contain" })}
/>

Not a Breaking Change

Existing code without classes continues to work exactly as before. Only users who pass classes AND want CSS to control object-fit benefit from this change.

Testing

Added tests to verify:

  • Default object-fit: cover when no class
  • No object-fit when class is provided
  • No object-fit when className is provided
  • Explicit objectFit prop works even with class

When a class or className prop is passed, skip the default object-fit: cover
inline style. This allows CSS classes to control object-fit without being
overridden by inline styles.

- No class → object-fit: cover (default, backward compatible)
- With class → no inline object-fit (CSS controls it)
- Explicit objectFit prop → always applied

Fixes ascorbic#283
@changeset-bot
Copy link

changeset-bot bot commented Jan 15, 2026

🦋 Changeset detected

Latest commit: 0ba76c4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 10 packages
Name Type
@unpic/core Patch
@unpic/angular Patch
@unpic/astro Patch
@unpic/lit Patch
@unpic/preact Patch
@unpic/react Patch
@unpic/solid Patch
@unpic/svelte Patch
@unpic/vue Patch
@unpic/webc Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify
Copy link

netlify bot commented Jan 15, 2026

Deploy Preview for unpic-angular ready!

Name Link
🔨 Latest commit 0ba76c4
🔍 Latest deploy log https://app.netlify.com/projects/unpic-angular/deploys/6968c5e4ab6f140008c8b024
😎 Deploy Preview https://deploy-preview-848--unpic-angular.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link

netlify bot commented Jan 15, 2026

Deploy Preview for unpic-next failed. Why did it fail? →

Name Link
🔨 Latest commit 0ba76c4
🔍 Latest deploy log https://app.netlify.com/projects/unpic-next/deploys/6968c5e4cd9b2e0008663826

@netlify
Copy link

netlify bot commented Jan 15, 2026

Deploy Preview for unpic-docs failed. Why did it fail? →

Name Link
🔨 Latest commit 0ba76c4
🔍 Latest deploy log https://app.netlify.com/projects/unpic-docs/deploys/6968c5e45fa7c700089fabe8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

objectFit props @unpic/solid

1 participant