Skip to content

Commit

Permalink
fix(button): is focused after click with :focusable="false", closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
07akioni committed Jun 10, 2022
1 parent 9bd1fdc commit 7063b04
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## NEXT_VERSION

### Fixes

- Fix `n-button` is focused after click with `:focusable="false"`, closes [#3071](https://github.com/TuSimple/naive-ui/issues/3071).

### Feats

- `n-tree-select` adds `arrow` slot, closes [#3084](https://github.com/TuSimple/naive-ui/issues/3084).
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## NEXT_VERSION

### Fixes

- 修复 `n-button` 在设定 `:focusable="false"` 后点击仍然会聚焦,关闭 [#3071](https://github.com/TuSimple/naive-ui/issues/3071)

### Feats

- `n-tree-select` 新增 `arrow` slot,关闭 [#3084](https://github.com/TuSimple/naive-ui/issues/3084)
Expand Down
9 changes: 7 additions & 2 deletions src/button/src/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,16 @@ const Button = defineComponent({
return props.focusable && !props.disabled
})
const handleMousedown = (e: MouseEvent): void => {
if (props.disabled || props.nativeFocusBehavior) {
if (props.nativeFocusBehavior) {
return
}
e.preventDefault()
// normally this won't be called if disabled (when tag is button)
// if not, we try to make it behave like a button
if (props.disabled) {
return
}
if (mergedFocusableRef.value) {
e.preventDefault()
selfElRef.value?.focus({ preventScroll: true })
}
}
Expand Down

0 comments on commit 7063b04

Please sign in to comment.