Shopify / polaris

Shopify’s design system to help us work together to build a great experience for all of our merchants.
https://polaris.shopify.com
Other
5.79k stars 1.17k forks source link

Radio options within a ChoiceList component cannot be selected #207

Closed chaddjohnson closed 6 years ago

chaddjohnson commented 6 years ago

Issue summary

Expected behavior

I should be able to select different radio options within a ChoiceList component.

Actual behavior

I am unable to select radio options in a ChoiceList component. Here I am unable to select the "Required" option:

screen shot 2017-10-24 at 4 43 04 pm

Steps to reproduce the problem

  1. Clone this fork.
  2. Run cd examples/webpack.
  3. Run rm yarn.lock.
  4. Run yarn install.
  5. Run yarn start.
  6. Visit http://localhost:8080.

You will see that only the default option, "Hidden," can be selected within the "Choice list" section.

Specifications


⚓️ We’re not accepting pull requests at this time
🗒 This repo is for reporting issues and feature requests only

charlesemarsh commented 6 years ago

+1 I'm getting this issue also, same thing with Checkboxs...

I noticed a console log of "Shopify.API.Bar.closeDropdown" when the checkbox and choices are clicked

chloerice commented 6 years ago

Hi @chaddjohnson, thanks for reaching out!

You've got two ChoiceLists in the webpack example in your Polaris clone. The second works as expected, but the first one copied from the Polaris style guide needs a couple of changes to work as expected (we're working on clearer style guide examples, sorry for any ambiguity).

With those two things fixed your first ChoiceList will be good to go.

One quick tip--when you use more than one ChoiceList, it's a good idea to use the optional name prop. The method you pass as the onChange prop receives two parameters. The first parameter is the array of values from selected choices and the second is the name given to the ChoiceList. You can use this name in your state to hold on to each ChoiceList's array of selected choices.

The code below has the changes mentioned above along with an update to your valueUpdater method to utilize the ChoiceList names given. @charlesemarsh I hope this helps you as well!

Click to view collapsed example code ```jsx import React, {Component} from 'react'; import { Layout, Page, FooterHelp, Card, Link, Button, FormLayout, TextField, AccountConnection, ChoiceList, SettingToggle, } from '@shopify/polaris'; class App extends Component { constructor(props) { super(props); this.state = { first: '', last: '', email: '', companyName: ['hidden'], termsOfService: [], connected: false, } } render() { const breadcrumbs = [ {content: 'Example apps'}, {content: 'webpack'}, ]; const primaryAction = {content: 'New product'}; const secondaryActions = [{content: 'Import', icon: 'import'}]; const choiceListItems = [ {label: 'I accept the Terms of Service', value: 'false'}, {label: 'I consent to receiving emails', value: 'false2'}, ]; return ( Upload your store’s logo, change colors and fonts, and more. {this.renderAccount()} For more details on Polaris, visit our styleguide. ); } valueUpdater(field) { return (value, name) => { if (field === 'checkboxes') return this.setState({[name]: value}); this.setState({[field]: value}); } } toggleConnection() { this.setState(({connected}) => ({connected: !connected})); } connectAccountMarkup() { return ( By clicking Connect, you are accepting Sample’s Terms and Conditions, including a commission rate of 15% on sales.

} />
); } disconnectAccountMarkup() { return ( Tom Ford} details="Account id: d587647ae4" /> ); } renderAccount() { return this.state.connected ? this.disconnectAccountMarkup() : this.connectAccountMarkup(); } } export default App; ```
chaddjohnson commented 6 years ago

Thank you @chloerice! That works.