I have button icon which is a separate component. I need to give the tab focus on this element after page is rendered. I am using Composition API in Vue 3. I tried adding ref to this component but it seems not working. here is the coding example:
<icon-button
name="edit"
:tooltip="$t('Change Profile Picture')"
@click="openEmployeeProfileModal"
size="small"
data-test="profile-modal-trigger"
class="prof-photo-edit-icon"
v-if="hasEditPermission"
/>
ref="profileEditIcon"add this to icon-button and inside onmount tried to foucsonMounted(() => { if (profileEditIcon.value) { profileEditIcon.value.focus(); } });autofocusit will do so using the root element of the component, which may or may not be focusable. If the element you're trying to focus is nested, you'd need some other strategy. A boolean prop for example, and then component code that sets focus when the prop is true. The idea you can't change the component is not a strong argument, imo. When functionality is tied conditionally to a prop, you can safely modify the component without causing any side effects elsewhere in your app where the component is used.