Skip to content

feat(runtime-dom): add popover api attributes #10977

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
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
13 changes: 13 additions & 0 deletions packages/compiler-core/__tests__/transforms/vOn.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -733,5 +733,18 @@ describe('compiler: transform v-on', () => {
},
})
})
it('Popover api @beforetoggle', () => {
const { node } = parseWithVOn(`<div @beforetoggle="test"></div>`, {
prefixIdentifiers: true,
})
const vnodeCall = node.codegenNode as VNodeCall
const properties = (vnodeCall.props as ObjectExpression).properties[0]
.value
expect(properties).toMatchObject({
type: NodeTypes.SIMPLE_EXPRESSION,
content: '_ctx.test',
isStatic: false,
})
})
})
})
15 changes: 13 additions & 2 deletions packages/runtime-dom/src/jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,11 @@ export interface HTMLAttributes extends AriaAttributes, EventHandlers<Events> {
* @see https://html.spec.whatwg.org/multipage/custom-elements.html#attr-is
*/
is?: string

// Popover API: https://developer.mozilla.org/en-US/docs/Web/API/Popover_API
popover?: true | 'auto' | 'manual'
onBeforetoggle?: Event
onToggle?: Event
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both should be ToggleEvent, also in DetailsHTMLAttributes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

upps, onBeforetoggle should be onBeforeToggle

}

type HTMLAttributeReferrerPolicy =
Expand Down Expand Up @@ -372,7 +377,7 @@ export interface BlockquoteHTMLAttributes extends HTMLAttributes {
cite?: string
}

export interface ButtonHTMLAttributes extends HTMLAttributes {
export interface ButtonHTMLAttributes extends PopoverHTMLAttributes {
autofocus?: Booleanish
disabled?: Booleanish
form?: string
Expand Down Expand Up @@ -404,6 +409,12 @@ export interface DataHTMLAttributes extends HTMLAttributes {
value?: string | ReadonlyArray<string> | number
}

/* Popover API: https://developer.mozilla.org/en-US/docs/Web/API/Popover_API */
export interface PopoverHTMLAttributes extends HTMLAttributes {
popovertarget?: string
popovertargetaction?: 'hide' | 'show' | 'toggle'
}

export interface DetailsHTMLAttributes extends HTMLAttributes {
open?: Booleanish
onToggle?: Event
Expand Down Expand Up @@ -512,7 +523,7 @@ export type InputTypeHTMLAttribute =
| 'week'
| (string & {})

export interface InputHTMLAttributes extends HTMLAttributes {
export interface InputHTMLAttributes extends PopoverHTMLAttributes {
accept?: string
alt?: string
autocomplete?: string
Expand Down
11 changes: 8 additions & 3 deletions packages/shared/src/domAttrConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@ import { makeMap } from './makeMap'
* - nomodule -> noModule
* - novalidate -> noValidate
* - readonly -> readOnly
* - popovertarget -> popoverTargetElement (TODO: how to map this?)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no idea how to handle this

* - popovertargetaction -> popoverTargetAction
*/
const specialBooleanAttrs = `itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly`
export const isSpecialBooleanAttr = /*#__PURE__*/ makeMap(specialBooleanAttrs)
export const isSpecialBooleanAttr = /*#__PURE__*/ makeMap(
`${specialBooleanAttrs},popovertarget,popovertargetaction`,
)

/**
* The full list is needed during SSR to produce the correct initial markup.
*/
export const isBooleanAttr = /*#__PURE__*/ makeMap(
specialBooleanAttrs +
`,async,autofocus,autoplay,controls,default,defer,disabled,hidden,` +
`inert,loop,open,required,reversed,scoped,seamless,` +
`inert,loop,open,popover,required,reversed,scoped,seamless,` +
`checked,muted,multiple,selected`,
)

Expand Down Expand Up @@ -70,7 +74,8 @@ export const isKnownHtmlAttr = /*#__PURE__*/ makeMap(
`height,hidden,high,href,hreflang,http-equiv,icon,id,importance,inert,integrity,` +
`ismap,itemprop,keytype,kind,label,lang,language,loading,list,loop,low,` +
`manifest,max,maxlength,minlength,media,min,multiple,muted,name,novalidate,` +
`open,optimum,pattern,ping,placeholder,poster,preload,radiogroup,readonly,` +
`open,optimum,pattern,ping,placeholder,popover,popovertarget,popovertargetaction,` +
`poster,preload,radiogroup,readonly,` +
`referrerpolicy,rel,required,reversed,rows,rowspan,sandbox,scope,scoped,` +
`selected,shape,size,sizes,slot,span,spellcheck,src,srcdoc,srclang,srcset,` +
`start,step,style,summary,tabindex,target,title,translate,type,usemap,` +
Expand Down