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

fix(DateField): rebuild focusable element Set on locale change #1132

Merged
merged 4 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 10 additions & 2 deletions packages/radix-vue/src/DateField/DateFieldRoot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const [injectDateFieldRootContext, provideDateFieldRootContext]
</script>

<script setup lang="ts">
import { computed, onMounted, ref, toRefs, watch } from 'vue'
import { computed, nextTick, onMounted, ref, toRefs, watch } from 'vue'
import { Primitive, usePrimitiveElement } from '@/Primitive'
import { useVModel } from '@vueuse/core'

Expand Down Expand Up @@ -179,8 +179,15 @@ const segmentContents = computed(() => allSegmentContent.value.arr)
const editableSegmentContents = computed(() => segmentContents.value.filter(({ part }) => part !== 'literal'))

watch(locale, (value) => {
if (formatter.getLocale() !== value)
if (formatter.getLocale() !== value) {
formatter.setLocale(value)
// Locale changed, so we need to clear the segment elements and re-get them (different order)
// Get the focusable elements again on the next tick
nextTick(() => {
segmentElements.value.clear()
Array.from(parentElement.value.querySelectorAll('[data-radix-vue-date-field-segment]')).filter(item => item.getAttribute('data-radix-vue-date-field-segment') !== 'literal').forEach(el => segmentElements.value.add(el as HTMLElement))
epr3 marked this conversation as resolved.
Show resolved Hide resolved
})
}
})

watch(modelValue, (_modelValue) => {
Expand Down Expand Up @@ -273,6 +280,7 @@ defineExpose({
:dir="dir"
@keydown.left.right="handleKeydown"
>
{{ currentSegmentIndex }}
<slot
:model-value="modelValue"
:segments="segmentContents"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import { Label } from '@/Label'
<Label
class="text-sm text-gray9"
for="date-field"
>Appointment (unavailable on 19th)</Label>
>
Appointment (unavailable on 19th)
</Label>
<DateFieldRoot
id="date-field"
v-slot="{ segments, isInvalid }"
Expand Down Expand Up @@ -40,7 +42,9 @@ import { Label } from '@/Label'
<span
v-if="isInvalid"
class="text-red-500"
>Invalidddd</span>
>
Invalid
</span>
</DateFieldRoot>
</div>
</Variant>
Expand Down
11 changes: 9 additions & 2 deletions packages/radix-vue/src/DateRangeField/DateRangeFieldRoot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const [injectDateRangeFieldRootContext, provideDateRangeFieldRootContext]
</script>

<script setup lang="ts">
import { computed, onMounted, ref, toRefs, watch } from 'vue'
import { computed, nextTick, onMounted, ref, toRefs, watch } from 'vue'
import { Primitive, usePrimitiveElement } from '@/Primitive'
import { useVModel } from '@vueuse/core'

Expand Down Expand Up @@ -264,8 +264,15 @@ watch([startValue, locale], ([_startValue]) => {
})

watch(locale, (value) => {
if (formatter.getLocale() !== value)
if (formatter.getLocale() !== value) {
formatter.setLocale(value)
// Locale changed, so we need to clear the segment elements and re-get them (different order)
// Get the focusable elements again on the next tick
nextTick(() => {
segmentElements.value.clear()
Array.from(parentElement.value.querySelectorAll('[data-radix-vue-date-field-segment]')).filter(item => item.getAttribute('data-radix-vue-date-field-segment') !== 'literal').forEach(el => segmentElements.value.add(el as HTMLElement))
epr3 marked this conversation as resolved.
Show resolved Hide resolved
})
}
})

watch(modelValue, (_modelValue) => {
Expand Down
Loading