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(core): make PTE active by default #8778

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ export const ptCustomBlockEditors = defineType({
},
{
name: 'initialActive',
title: 'Activated on mount (no click required)',
title: 'Inactivate on mount (click required)',
type: 'array',
components: {
input: (props: PortableTextInputProps) => <BlockEditor {...props} initialActive />,
input: (props: PortableTextInputProps) => <BlockEditor {...props} initialActive={false} />,
},
of: [{type: 'block'}],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {InputStory} from './InputStory'
test.describe('Portable Text Input', () => {
test.describe('Activation', () => {
test(`Show call to action on focus`, async ({mount}) => {
const component = await mount(<InputStory />)
const component = await mount(<InputStory ptInputProps={{initialActive: false}} />)
const $portableTextInput = component.getByTestId('field-body')
const $activeOverlay = $portableTextInput.getByTestId('activate-overlay')

Expand All @@ -18,7 +18,7 @@ test.describe('Portable Text Input', () => {
})

test(`Show call to action on hover`, async ({mount}) => {
const component = await mount(<InputStory />)
const component = await mount(<InputStory ptInputProps={{initialActive: false}} />)
const $portableTextInput = component.getByTestId('field-body')
const $activeOverlay = $portableTextInput.getByTestId('activate-overlay')

Expand All @@ -34,6 +34,14 @@ test.describe('Portable Text Input', () => {
const $activeOverlay = $portableTextInput.getByTestId('activate-overlay')
await expect($activeOverlay).not.toBeAttached()
})

test(`Immediately activate on mount when 'initialActive' is unset`, async ({mount}) => {
const component = await mount(<InputStory />)

const $portableTextInput = component.getByTestId('field-body')
const $activeOverlay = $portableTextInput.getByTestId('activate-overlay')
await expect($activeOverlay).not.toBeAttached()
})
})

test.describe('Placeholder', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export function PortableTextInput(props: PortableTextInputProps): ReactNode {
const [ignoreValidationError, setIgnoreValidationError] = useState(false)
const [invalidValue, setInvalidValue] = useState<InvalidValue | null>(null)
const [isFullscreen, setIsFullscreen] = useState(initialFullscreen ?? false)
const [isActive, setIsActive] = useState(initialActive ?? false)
const [isActive, setIsActive] = useState(initialActive ?? true)
const [hasFocusWithin, setHasFocusWithin] = useState(false)
const [ready, setReady] = useState(false)
const telemetry = useTelemetry()
Expand Down
2 changes: 1 addition & 1 deletion packages/sanity/src/core/form/types/inputProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ export interface PortableTextInputProps
hotkeys?: HotkeyOptions
/**
* Whether the input is activated and should receive events on mount.
* By default, PTE inputs need to be manually activated by focusing them.
* By default, this value is set to `true`
*/
initialActive?: boolean
/**
Expand Down
Loading