Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 1 | <template> |
| 2 | <div class="input-password-toggle-container"> |
| 3 | <slot></slot> |
| 4 | <b-button |
Yoshie Muranaka | 547b5fc | 2020-02-24 15:42:40 -0800 | [diff] [blame] | 5 | :aria-label="$t('global.ariaLabel.showPassword')" |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 6 | variant="link" |
SurenNeware | dc618a8 | 2020-08-17 18:42:20 +0530 | [diff] [blame] | 7 | class="input-action-btn" |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 8 | :class="{ isVisible: isVisible }" |
| 9 | @click="toggleVisibility" |
| 10 | > |
Dixsie Wolmers | d2ac76d | 2020-08-26 17:23:45 -0500 | [diff] [blame] | 11 | <icon-view-off |
| 12 | v-if="isVisible" |
| 13 | aria-hidden="true" |
| 14 | :title="$t('global.ariaLabel.hidePassword')" |
| 15 | /> |
| 16 | <icon-view |
| 17 | v-else |
| 18 | aria-hidden="true" |
| 19 | :title="$t('global.ariaLabel.showPassword')" |
| 20 | /> |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 21 | </b-button> |
| 22 | </div> |
| 23 | </template> |
| 24 | |
| 25 | <script> |
| 26 | import IconView from '@carbon/icons-vue/es/view/20'; |
| 27 | import IconViewOff from '@carbon/icons-vue/es/view--off/20'; |
| 28 | |
| 29 | export default { |
| 30 | name: 'InputPasswordToggle', |
| 31 | components: { IconView, IconViewOff }, |
| 32 | data() { |
| 33 | return { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 34 | isVisible: false, |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 35 | }; |
| 36 | }, |
| 37 | methods: { |
| 38 | toggleVisibility() { |
| 39 | const firstChild = this.$children[0]; |
| 40 | const inputEl = firstChild ? firstChild.$el : null; |
| 41 | |
| 42 | this.isVisible = !this.isVisible; |
| 43 | |
| 44 | if (inputEl.nodeName === 'INPUT') { |
| 45 | inputEl.type = this.isVisible ? 'text' : 'password'; |
| 46 | } |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 47 | }, |
| 48 | }, |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 49 | }; |
| 50 | </script> |
| 51 | |
| 52 | <style lang="scss" scoped> |
| 53 | .input-password-toggle-container { |
| 54 | position: relative; |
| 55 | } |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 56 | </style> |