Skip to content

Commit

Permalink
feat(weapp): 让 Input 支持 KeyboardAccessory,fix #11510
Browse files Browse the repository at this point in the history
  • Loading branch information
Chen-jj authored and ZakaryCode committed Mar 29, 2022
1 parent 8e98aa7 commit 15f8295
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
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

0 comments on commit 15f8295

Please sign in to comment.