Material-components-web: MDCSelect wrong setStyle width

Created on 3 Jul 2017  路  9Comments  路  Source: material-components/material-components-web

What MDC-Web Version are you using?

[email protected]

What browser(s) is this bug affecting?

Only tested chrome and firefox on GNOME

What OS are you using?

Ubuntu Gnome 17.04

What are the steps to reproduce the bug?

  • MDCSelect.attachTo(element)
  • done.

What is the expected behavior?

mdc-select width should be correct

What is the actual behavior?

returns short values.

Any other information you believe would be useful?

When not yet attaching an instance, the element looks good. Once initialized, the selected text cannot be seen.

bug

Most helpful comment

Do you do somthing like

* {
  box-sizing: border-box;
}

'cause then that's your problem.
The width is calculated as content-box

All 9 comments

Would you mind uploading a few screen shots of this behavior?

Screenshot:

Temporary fix: empty function for setStyle

Related issue #1335

I fixed this by patching select, to allow spread them to the whole container width

import {select} from 'material-components-web';

class MDCSelect extends select.MDCSelect {
  getDefaultFoundation() {
    let foundation = super.getDefaultFoundation(),
        super_setMenuStyle = foundation.setMenuStylesForOpenAtIndex_

    foundation.resize = function() {
      /* no action here */
    }

    foundation.setMenuStylesForOpenAtIndex_ = function (index) {
      super_setMenuStyle.call(foundation, index)

      const rect = foundation.adapter_.computeBoundingRect()
      foundation.adapter_.setMenuElStyle('width', `${rect.width}px`);
    }

    return foundation
  }
}

same issue

For some reason, it doesn't calculate my longest option correctly. It's always 24 px short (which is also the padding size).

screen shot 2017-12-04 at 1 36 06 pm

Do you do somthing like

* {
  box-sizing: border-box;
}

'cause then that's your problem.
The width is calculated as content-box

Ahh wow! Thanks!

That's in the default css generated by preact-cli. Removing it fixed my issue.

Closing this as obsolete.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

traviskaufman picture traviskaufman  路  3Comments

16rajumane picture 16rajumane  路  3Comments

trimox picture trimox  路  4Comments

patrickrodee picture patrickrodee  路  3Comments