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

feat(weapp): 让 Input 支持 KeyboardAccessory,fix #11510 #11531

Merged
merged 1 commit into from
Mar 29, 2022
Merged
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
9 changes: 6 additions & 3 deletions packages/taro-weapp/src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default class Weapp extends TaroPlatformBase {
this.template = new Template(pluginOptions)
this.setupTransaction.addWrapper({
close () {
this.modifyTemplate()
this.modifyTemplate(pluginOptions)
this.modifyWebpackConfig()
}
})
Expand All @@ -43,12 +43,15 @@ export default class Weapp extends TaroPlatformBase {
/**
* 增加组件或修改组件属性
*/
modifyTemplate () {
modifyTemplate (pluginOptions?: IOptions) {
const template = this.template
template.mergeComponents(this.ctx, components)
template.voidElements.add('voip-room')
template.voidElements.delete('textarea')
template.focusComponents.add('editor')
if (pluginOptions?.enablekeyboardAccessory) {
template.voidElements.delete('input')
template.voidElements.delete('textarea')
}
}

/**
Expand Down
8 changes: 4 additions & 4 deletions packages/taro-weapp/src/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class Template extends UnRecursiveTemplate {
return `function(i, prefix) {
var s = i.focus !== undefined ? 'focus' : 'blur'
var r = prefix + i.${nn} + '_' + s
if (i.nn === 'textarea' && i.cn[0] && i.cn[0].nn === 'keyboard-accessory') {
if ((i.nn === 'textarea' || i.nn === 'input') && i.cn[0] && i.cn[0].nn === 'keyboard-accessory') {
r = r + '_ka'
}
return r
Expand All @@ -56,7 +56,7 @@ export class Template extends UnRecursiveTemplate {
modifyTemplateResult = (res: string, nodeName: string, _level, children) => {
if (nodeName === 'keyboard-accessory') return ''

if (nodeName === 'textarea' && this.pluginOptions.enablekeyboardAccessory) {
if ((nodeName === 'textarea' || nodeName === 'input') && this.pluginOptions.enablekeyboardAccessory) {
const list = res.split('</template>')

const target = `
Expand All @@ -69,11 +69,11 @@ export class Template extends UnRecursiveTemplate {

const templateFocus = list[1]
.replace(children, target)
.replace('_textarea_focus', '_textarea_focus_ka')
.replace(`_${nodeName}_focus`, `_${nodeName}_focus_ka`)

const templateBlur = list[2]
.replace(children, target)
.replace('_textarea_blur', '_textarea_blur_ka')
.replace(`_${nodeName}_blur`, `_${nodeName}_blur_ka`)

list.splice(3, 0, templateFocus, templateBlur)
return list.join('</template>')
Expand Down