Skip to content
Draft
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/bright-eyes-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@soramitsu-ui/ui': minor
---

**feat**(`STextField`): expose internal `<input>` element ref via `input` field
21 changes: 21 additions & 0 deletions packages/ui/cypress/component/STextField.spec.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Status } from '@/types'

import { VueTestUtils } from 'cypress/vue'
import { STextField } from '@/lib'
import { Component } from 'vue'

const findInput = () => cy.get('input')
const findLabel = () => cy.get('label')
Expand Down Expand Up @@ -347,3 +348,23 @@ describe('Passing extra attributes', () => {
findInput().should('have.attr', 'data-count', 1)
})
})

it('`<input>` is accessible throught the component instance', () => {
cy.mount({
setup() {
const componentRef = ref<null | (Component & { input: null | HTMLInputElement })>(null)
const inputElement = computed(() => componentRef.value?.input ?? null)

watch(inputElement, (el) => {
if (el) {
el.value = 'You got me'
}
})

return { componentRef }
},
template: `<STextField ref="componentRef" />`,
})

findInput().should('have.value', 'You got me')
})
7 changes: 7 additions & 0 deletions packages/ui/src/components/TextField/STextField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ function onInput(e: Event) {
}
}

const inputElement = templateRef<null | HTMLInputElement>('input')

defineExpose({
input: inputElement,
})

const isValueEmpty = computed(() => !model.value)
const isFocused = ref(false)
const labelTypographyClass = computed(() => (!isFocused.value && isValueEmpty.value ? 'sora-tpg-p3' : 'sora-tpg-p4'))
Expand Down Expand Up @@ -229,6 +235,7 @@ const inputType = computed(() =>

<input
:id="id"
ref="input"
:value="model"
:type="inputType"
:disabled="disabled"
Expand Down