Skip to content

Commit

Permalink
chore: chanegs syntax for floatingLabel default prop value
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-boyd committed Mar 22, 2024
1 parent d266ab0 commit b83de53
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
28 changes: 12 additions & 16 deletions packages/addons/src/plugins/floatingLabels/floatingLabelsPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
FormKitPlugin,
FormKitSectionsSchema,
} from '@formkit/core'
import { clone, whenAvailable, undefine } from '@formkit/utils'
import { clone, whenAvailable } from '@formkit/utils'
import { findSection } from '@formkit/inputs'

/**
Expand Down Expand Up @@ -77,21 +77,17 @@ export function createFloatingLabelsPlugin(
): FormKitPlugin {
const floatingLabelsPlugin = (node: FormKitNode) => {
let nodeEl: HTMLElement | null = null
node.addProps([
'floatingLabel',
'_labelBackgroundColor',
'_labelOffset',
'_offsetCalculated',
])

node.props.floatingLabel = undefine(node.props.floatingLabel)

const useFloatingLabels =
typeof node.props.floatingLabel === 'boolean'
? node.props.floatingLabel
: typeof FloatingLabelsOptions?.useAsDefault === 'boolean'
? FloatingLabelsOptions?.useAsDefault
: false
node.addProps({
floatingLabel: {
boolean: true,
default: !!FloatingLabelsOptions?.useAsDefault,
},
_labelBackgroundColor: {},
_labelOffset: {},
_offsetCalculated: {},
})

const useFloatingLabels = node.props.floatingLabel

if (useFloatingLabels && node.context) {
node.on('created', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/nuxt/playground/pages/floating-labels.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ import '@formkit/addons/css/floatingLabels.css'
label="test"
/>
<FormKit
:plugins="[createFloatingLabelsPlugin()]"
:plugins="[createFloatingLabelsPlugin({ useAsDefault: true })]"
type="email"
name="email"
label="test"
floating-label="false"
/>
<FormKit
:plugins="[createFloatingLabelsPlugin()]"
:plugins="[createFloatingLabelsPlugin({ useAsDefault: true })]"
type="email"
name="email"
label="test"
Expand Down

0 comments on commit b83de53

Please sign in to comment.