Semantic-Org / Semantic-UI-React

The official Semantic-UI-React integration
https://react.semantic-ui.com
MIT License
13.22k stars 4.05k forks source link

Tabular menu items do not display special characters #1340

Closed achimkoellner closed 7 years ago

achimkoellner commented 7 years ago
import React from 'react';
import { Menu } from 'semantic-ui-react';

class MyMenu extends React.Component {
    render () { 
        return (
            <Menu tabular attached="top">
                <Menu.Item name="Übersicht" active/>
                <Menu.Item name="Würstchen" />
                <Menu.Item name="Lärchen" />
            </Menu>
        );
    }
})

export default MyMenu

The code above will render Tabs labeled with "Ubersicht", "Wurstchen" and "Larchen".

levithomason commented 7 years ago

Pasting this code into the docs produces:

image

Fixing that error produces:

image

achimkoellner commented 7 years ago

Hi levithomason, but look it does not display the special characters in this example. It displays Ubersicht instead of Übersicht

levithomason commented 7 years ago

Ah, I see. Yes, this is because if no content is provided for the menu item, the name is Start Cased and used for the content: _.startCase(name). That process appears to deburr the characters.

To keep them, you should explicitly set the content to the special characters you want to see:

image

The name prop is the "Internal name of the MenuItem". It is the programmatic name used in the onItemClick, you can see the name usage with the callback in the 4th Menu example in the docs:

import React, { Component } from 'react'
import { Menu } from 'semantic-ui-react'

export default class MenuExampleNameProp extends Component {
  state = {}

  handleItemClick = (e, { name }) => this.setState({ activeItem: name })

  render() {
    const { activeItem } = this.state

    return (
      <Menu>
        <Menu.Item
          name='editorials'
          active={activeItem === 'Editorials'}
          onClick={this.handleItemClick}
        />
        <Menu.Item
          name='reviews'
          active={activeItem === 'Reviews'}
          onClick={this.handleItemClick}
        />
        <Menu.Item
          name='upcomingEvents'
          active={activeItem === 'upcomingEvents'}
          onClick={this.handleItemClick}
        />
      </Menu>
    )
  }
}

Notice also how these names are camelCased, but the menu displays them Start Cased in the rendered items.

levithomason commented 7 years ago

BTW, this is confusing for sure. I'm open to redesign here. Less magic and more explicit would be good. I'm not sure we even need a name prop at all in this workflow. I don't have time for it, but I would support an effor to clean this up, making it more simple, more explicit, and not transforming values like this.

achimkoellner commented 7 years ago

However Levi, it works thanks a ton!

jarben commented 7 years ago

Just burned a few hours before finding this issue. Would be great if name works with utf-8!

levithomason commented 7 years ago

PRs welcome! See the CONTRIBUTING.md setup and more info.

Cicko commented 7 years ago

How Can I set the content of each tab? There are no examples of it.

levithomason commented 7 years ago

Usage questions are best answered on gitter, see link in the README badges. That said, I'm not exactly sure what you are asking.