Advertisement
Guest User

Untitled

a guest
May 16th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.48 KB | None | 0 0
  1. diff --git a/ui/webui/resources/cr_elements/cr_tabs/cr_tabs.html b/ui/webui/resources/cr_elements/cr_tabs/cr_tabs.html
  2. index c0b077d19ded..886bd09c282b 100644
  3. --- a/ui/webui/resources/cr_elements/cr_tabs/cr_tabs.html
  4. +++ b/ui/webui/resources/cr_elements/cr_tabs/cr_tabs.html
  5. @@ -74,7 +74,7 @@
  6.      </style>
  7.      <template is="dom-repeat" items="[[tabNames]]"
  8.          on-dom-change="updateSelectionBar_">
  9. -      <div class$="tab [[getCssClass_(index, selected)]]" role="tab"
  10. +      <div class="tab" role="tab"
  11.            aria-selected$="[[getAriaSelected_(index, selected)]]"
  12.            tabindex$="[[getTabIndex_(index, selected)]]" on-click="onTabClick_">
  13.          [[item]]
  14. diff --git a/ui/webui/resources/cr_elements/cr_tabs/cr_tabs.js b/ui/webui/resources/cr_elements/cr_tabs/cr_tabs.js
  15. index 67bf891fc8b2..c94b3d1e7278 100644
  16. --- a/ui/webui/resources/cr_elements/cr_tabs/cr_tabs.js
  17. +++ b/ui/webui/resources/cr_elements/cr_tabs/cr_tabs.js
  18. @@ -57,10 +57,6 @@ Polymer({
  19.    /** @override */
  20.    attached: function() {
  21.      this.isRtl_ = this.matches(':host-context([dir=rtl]) cr-tabs');
  22. -    // When handling the initial 'dom-change' event, it's possible for the
  23. -    // selected tab to exist and not yet be fully rendered. This will result in
  24. -    // the selection bar not rendering correctly.
  25. -    setTimeout(() => this.updateSelectionBar_());
  26.    },
  27.  
  28.    /**
  29. @@ -72,15 +68,6 @@ Polymer({
  30.      return this.selected == index ? 'true' : 'false';
  31.    },
  32.  
  33. -  /**
  34. -   * @param {number} index
  35. -   * @return {string}
  36. -   * @private
  37. -   */
  38. -  getCssClass_: function(index) {
  39. -    return this.selected == index ? 'selected' : '';
  40. -  },
  41. -
  42.    /**
  43.     * @param {number} index
  44.     * @return {number}
  45. @@ -135,25 +122,40 @@ Polymer({
  46.    },
  47.  
  48.    /** @private */
  49. -  updateSelectionBar_: function() {
  50. -    const selectedTab = this.$$('.selected');
  51. -    if (!selectedTab) {
  52. +  updateSelectionBar_: function(current, previous) {
  53. +    const tabs = this.shadowRoot.querySelectorAll('.tab');
  54. +
  55. +    if (tabs.length === 0) {
  56. +      // The dom-repeat has not been rendered yet. Do nothing here.
  57. +      // |onDomChange_| event will re-trigger this when ready.
  58.        return;
  59.      }
  60.  
  61. +    tabs.forEach((tab, i) => {
  62. +      tab.classList.toggle('selected', i === this.selected);
  63. +    });
  64. +
  65. +    const selectedTab = this.$$('.selected');
  66.      selectedTab.focus();
  67.      this.$.selectionBar.classList.remove('expand', 'contract');
  68. -    const {offsetLeft: selectedLeft, offsetWidth: selectedWidth} = selectedTab;
  69.      const oldValue = this.lastSelected_;
  70.      this.lastSelected_ = this.selected;
  71.  
  72.      // If there is no previously selected tab or the tab has not changed,
  73.      // underline the selected tab instantly.
  74.      if (oldValue == null || oldValue == this.selected) {
  75. -      this.transformSelectionBar_(selectedLeft, selectedWidth);
  76. +      // When handling the initial 'dom-change' event, it's possible for the
  77. +      // selected tab to exist and not yet be fully rendered. This will result in
  78. +      // the selection bar not rendering correctly.
  79. +      window.setTimeout(() => {
  80. +        this.transformSelectionBar_(
  81. +            selectedTab.offsetLeft, selectedTab.offsetWidth);
  82. +      }, 0);
  83.        return;
  84.      }
  85.  
  86. +    const {offsetLeft: selectedLeft, offsetWidth: selectedWidth} = selectedTab;
  87. +
  88.      // Expand bar to underline the last selected tab, the newly selected tab and
  89.      // everything in between. After expansion is complete, contract bar to
  90.      // underline the selected tab.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement