Sharlaan / material-ui-superselectfield

multiselection autocomplete dropdown component for Material-UI
https://sharlaan.github.io/material-ui-superselectfield
MIT License
266 stars 92 forks source link

Add feature menuSelectionCallback to pull updatedValues onClick of a ListItem #113

Closed jwmann closed 6 years ago

jwmann commented 6 years ago

Fixes #112

codecov-io commented 6 years ago

Codecov Report

Merging #113 into master will decrease coverage by 0.39%. The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #113     +/-   ##
=========================================
- Coverage   40.97%   40.57%   -0.4%     
=========================================
  Files           6        6             
  Lines         205      207      +2     
=========================================
  Hits           84       84             
- Misses        121      123      +2
Impacted Files Coverage Δ
src/types/index.js 33.33% <ø> (ø)
src/defaultProps.js 53.84% <ø> (ø)
src/SuperSelectField.js 38.21% <0%> (ø)
...terial-ui-superselectfield/src/SuperSelectField.js
...an/material-ui-superselectfield/src/types/index.js
...Sharlaan/material-ui-superselectfield/src/utils.js
.../material-ui-superselectfield/src/FloatingLabel.js
...ial-ui-superselectfield/src/SelectionsPresenter.js
...n/material-ui-superselectfield/src/defaultProps.js
src/utils.js 36% <0%> (ø)
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 2782171...f146b4b. Read the comment docs.

jwmann commented 6 years ago

I'm trying to write some tests for this but it seems almost impossible.

describe('menuSelectionCallback', () => {
  it('should return updatedValues', () => {
    const wrapper = shallowWithContext(<SuperSelectField showAutocompleteThreshold="always">{testChildren}</SuperSelectField>)
    wrapper.simulate('click')
    const firstChild = wrapper.find('ListItem').first()
    firstChild.simulate('click', {
      preventDefault: () => {
      },
    });
    expect( wrapper.instance().props.menuSelectionCallback ).toHaveBeenCalled()
  })
})

Keep getting an error TypeError: Cannot read property 'focus' of undefined or undefined is not an object (evaluating '_this.root.focus')

I also just noticed #23 I didn't realize this was a hot button issue. I do think setting the state based onClick rather than when the menu is closed is necessary. Not only that, but the original docs were actually incorrect as it said the state was change onClick but that's not the case with onChange.

jwmann commented 6 years ago

Unfortunately because of #105 I can't even run this on my project without published merges. I'm open to discussing these changes as well as test coverage. Hopefully we can resolve this without breaking any backwards compatibility.

Sharlaan commented 6 years ago

solved with #119