-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Button: Getting anchor native props if href prop is specified #9456
Conversation
Component perf results:
|
// TODO: 'href' is anchor property... consider getNativeProps by root type | ||
const buttonProps = { ...getNativeProps(rest, buttonProperties) }; | ||
const buttonProps = { ...getNativeProps(rest, propertiesType) }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TS3.5 is requiring explicit types for getNativeProps
calls (due to deficiencies in getNativeProps
typing that I've documented there) so you may have to add one here. You can search any other use of getNativeProps
for examples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just swap the HTMLElement typing.
…c-react into buttonNativeProps
Exceeds Tolerance Exceeds Baseline Below Baseline 1 kB = 1000 bytes |
import { Icon } from '../../utilities/factoryComponents'; | ||
|
||
import { IButtonComponent, IButtonProps, IButtonRootElements, IButtonSlots, IButtonViewProps } from './Button.types'; | ||
|
||
export const ButtonView: IButtonComponent['view'] = props => { | ||
const { icon, content, children, disabled, onClick, allowDisabledFocus, ariaLabel, keytipProps, buttonRef, ...rest } = props; | ||
|
||
const rootType = _deriveRootType(props); | ||
const htmlType = rootType === 'a' ? 'link' : 'button'; | ||
const propertiesType = rootType === 'a' ? anchorProperties : buttonProperties; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is starting to make me feel that this view is doing too much and button vs anchor should be split out into smaller components. That way you can check once if there is an href and then have each component handle it's own props correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe there should be a function like _deriveRootState or something that bundles all that work into one place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about the second option you mentioned yesterday and I think I'm going to go ahead and combine those 3 lines into one function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joschect Updated with the function approach bundling that work 👍
🎉 Handy links: |
* master: (46 commits) Enable conditional rendering of page sections depending on query present in the url to enable iframe rendering of examples on docs.microsoft OUFR portal (microsoft#9438) Applying package updates. Make more examples exportable to codepen (microsoft#9468) Fix create-package script (microsoft#9491) Card: Making elevation themable by using the effects from theme instead of directly referencing Depths (microsoft#9472) Revert "Tooltip: improve perf by preventing all render until after de… (microsoft#9495) a11y-tests: Run a11y tests on all component examples (microsoft#9479) Website (mobile): Add source code links, remove generic library link (microsoft#9487) Facepile - Adding OnRenderPersona and OnRenderPersonaCoin as optional… (microsoft#9480) Applying package updates. Accessibility improvement for DetailsList while placeholder data is being displayed (microsoft#9484) Button: Getting anchor native props if href prop is specified (microsoft#9456) Fabric website: add documentation entry points. (microsoft#9477) Website: Add overview and control request sections to mobile pages. (microsoft#9483) Fixing some styling bugs in theme designer: theme slots pivot was not centered & Main part of the page with the 3 stacks had a margin when it was unnecessary. Also cleaned up the code by creating a separate component for ThemeSlots that does the pivoting. (microsoft#9458) Only run KeytipManager update when relevant keytip props have changed (microsoft#9414) Theme colors page (microsoft#9369) Prevent Callout from being dismissed after mouse pressed inside but released outside (microsoft#9415) Add data viz separator for HorizontalBarChart (microsoft#9482) Applying package updates. ...
Pull request checklist
$ npm run change
Description of changes
This PR gets
anchorProperties
instead ofbuttonProperties
if thehref
prop has been specified for theButton
component. Examples and snapshot tests have been added for this scenario as part of this PR.I also realized that a lot of snapshot tests were not running correctly because it was missing the call to the
toMatchSnapshot
function, so this PR also fixes that.Focus areas to test
(optional)
Microsoft Reviewers: Open in CodeFlow