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

refactor(App): remove default locale handling #2760

Open
wants to merge 2 commits into
base: v3
Choose a base branch
from

Conversation

AnOrdinaryPeople
Copy link
Contributor

πŸ”— Linked issue

Resolves #2759

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This PR removes the default locale handling from the App component, as this functionality is already managed by the useLocale composable at:

return buildLocaleContext(computed(() => locale.value || en))

Additionally, the value of dir prop is set to be optional because current default language is English, and Radix Vue already provides a default ltr value for it: https://www.radix-vue.com/utilities/config-provider.html#config-provider-1

Example results of locale prop from App component:

  • With undefined value
    image
  • With fr value
    image
  • With ar value
    image

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

Copy link

pkg-pr-new bot commented Nov 25, 2024

npm i https://pkg.pr.new/@nuxt/ui@2760

commit: ba1d3d4

@benjamincanac benjamincanac added the v3 #1289 label Nov 25, 2024
@hywax
Copy link
Contributor

hywax commented Nov 26, 2024

This is a valid point. Only you need to delete the comment in useLocale.ts from line 13-15

@AnOrdinaryPeople
Copy link
Contributor Author

Got it, I'll remove the comment

@@ -37,12 +36,12 @@ const configProviderProps = useForwardProps(reactivePick(props, 'scrollBody'))
const tooltipProps = toRef(() => props.tooltip)
const toasterProps = toRef(() => props.toaster)
const locale = computed(() => props.locale || en)
const locale = toRef(() => props.locale)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is toRef here necessary? locale is already reactive (since it is a prop)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can remove it!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, its because the localeContextInjectionKey accepts ref type, you can see it at:

export const localeContextInjectionKey: InjectionKey<Ref<Locale | undefined>> = Symbol('nuxt-ui.locale-context')

And about replacement from computed to toRef just only for consistency like the code above (tooltipProps and toasterProps), or should I revert to the computed then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I've got a problem here, the reactivity does working for dir but for any attributes for aria-* doesn't updating. For example:
Screenshot from 2024-11-26 20-59-46
And here's the updated code:

  • App.vue
    provide(localeContextInjectionKey, props.locale)
  • useLocale.ts
    export const localeContextInjectionKey: InjectionKey<Locale | undefined> = Symbol('nuxt-ui.locale-context')
    
    const _useLocale = (localeOverrides?: Locale | undefined) => {
      const locale = localeOverrides || inject(localeContextInjectionKey, undefined)!
    
      return buildLocaleContext(computed(() => locale || en))
    }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benjamincanac I'll see what the problem might be today or tomorrow and I'll report back

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep the toRef on App component since it works as expected, similar to what's described in the PR πŸ€”

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v3 #1289
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants