seanmcp / a11y-react-emoji Goto Github PK
View Code? Open in Web Editor NEW⚛️ An accessible Emoji component for React applications
Home Page: https://npmjs.com/package/a11y-react-emoji
License: MIT License
⚛️ An accessible Emoji component for React applications
Home Page: https://npmjs.com/package/a11y-react-emoji
License: MIT License
Ouch. Why is that? It seems like this lib should just be generating the correct html, like <span aria-label="positive" role="img">😁</span>
?
a11y-react-emoji/src/Emoji.test.ts
Line 6 in dffb4c8
Check to make sure that className
makes it to the final component.
When no label
prop is specified, the type of aria-label
should be undefined
instead of null
. Same goes for aria-hidden
when a label
is passed. This aligns with the official React type definitions for both attributes.
Type of aria-label
:
(JSX attribute) React.AriaAttributes['aria-label']?: string | undefined
Type of aria-hidden
:
(JSX attribute) React.AriaAttributes['aria-hidden']?: boolean | "true" | "false" | undefined
Lines 23 to 24 in 24266b0
See example: kirillpchernov/a11y-react-emoji@711aa1a
The current API for Emoji
requires you pass the emoji string to a symbol
prop. This is fine and doesn't need changing.
But what about also accepting the emoji passed as children? The new API would work like this:
<Emoji label="a buzzing bee">🐝</Emoji>
I think children is what the user would expect. The tradeoff is that we would need to handle the scenario where both symbol
and children
are passed. Who would win in that instance? Or should an error be thrown?
Follow the pattern here: https://keepachangelog.com/en/1.0.0/
Will the pending release of React 17, the React peer dependencies should be updated. I think >=16
should world, but it's worth testing out.
I like the format from "Keep a Changelog", but I'm open to other suggestions.
Questions to consider:
Find the earliest version of React that still works with a11y-react-emoji
and update the peer dependency accordingly.
Use caret to peg peer dependency for react
in the same manner as react-dom
. See this answer on StackOverflow.
I believe the EmojiProps
interface should extend the HTMLSpanElement
type. That way, additional <span>
attributes can be directly passed as props to the Emoji
component without raising type errors in TypeScript.
Recommendation:
interface EmojiProps extends React.HTMLAttributes<HTMLSpanElement> {
label?: string;
symbol: string;
}
Safely permits usage such as:
<Emoji label="dog" symbol="🐕" className="className" />
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.