Appearance
Appearance
import Textarea from '~/ui/Textarea.vue'Textareas are input blocks that enable users to write formatted text (format: Markdown). These blocks are used throughout the Funkwhale interface for entering item descriptions, moderation notes, and custom notifications.
const {
charLimit = Infinity,
placeholder = '',
initialLines = 3,
uiSunken = useContext().value.uiSunken ?? undefined,
...props
} = defineProps<WithAttributes<{
class: {
justify?: 'justify-start'
}
label?: string
placeholder?: string
charLimit?: number
initialLines?: number | string
autofocus?: boolean
required?: boolean
disabled?: boolean
uiSunken?: boolean
}>>()const model = defineModel<string>({ required: true })Create a textarea and attach its input to a value using a v-model of type string (required):
const text = ref('# Funkwhale\n\n- Design system')<Textarea v-model="text" />NOTE
To convey the intent of the input field, add either a text label (label prop) or a custom, screenreader-friendly label template. Read more on form field labelling
<Spacer />
<template #label>
About my music
<Link href="/" class="color-primary-solid shape-circle" ui-block-size="24">
<Icon icon="bi:info-lg" />
</Link>
<span style="color:red;">(required)</span>
</template>
</Textarea>If you just have a string, we have a convenience prop, so instead you can write:
<Spacer />
<Textarea v-model="text" label="About my music" />Note that the label text sits atop of the upper end of the component. This way, you can define the distance between baselines (the vertical rhythm) with spacers or gaps.
<Textarea
v-model="text"
placeholder="Describe this track here…"
/>You can set the maximum length (in characters) that a user can enter in a textarea by passing a charLimit prop.
<Textarea v-model="text" :charLimit="20" />Caveats
Specify the number of lines with the initial-lines prop (the default is 5):
<Textarea v-model="text" initial-lines="1" />If you add the autofocus attribute, the text input field will receive focus as soon as it is rendered on the page. Make sure to only add this prop to a single component per page!
The required attribute prevents the submit button of this form.
Make sure to also add an indicator such as the text "required" or a star to prevent confusion.
See mdn on the required attribute if you want to know more.
Any prop that is not declared in the Props type will be added to the <textarea> element directly. See mdn on textarea attributes here. Examples: autocomplete, cols, minlength, readonly, wrap, disabled etc.
By default, there are text formatting buttons and a 'preview' toggle button in the toolbar. You can add custom content there by adding them into the default slot. They will be drawn before the preview button.
<Textarea v-model="text">
<Spacer no-size grow />
<Button
v-if="text !== ''"
@click.prevent="reset()"
>
<Icon icon="bi:arrow-counterclockwise" />
Reset
</Button>
</Textarea>Using this component
<Textarea
v-model="text"
label="Your message"
/>Guide: Creating accessible forms