callstack / react-native-paper

Material Design for React Native (Android & iOS)
https://reactnativepaper.com
MIT License
12.5k stars 2.05k forks source link

Web: Unwanted TextInput focus outline #1377

Closed globophobe closed 4 years ago

globophobe commented 4 years ago

Ask your Question

I thought this would remove the focus outline style with react-native-web, but it doesn't 😞.

const styles = StyleSheet.create({
  textInput: {
    outlineStyle: "none",
    outlineWidth: 0,
    outlineColor: "transparent"
  }
});

<TextInput style={styles.textInput} />

How can I remove it?

globophobe commented 4 years ago

Fixed wtih Emotion Global Styles .

actuallymentor commented 4 years ago

Fixed wtih Emotion Global Styles .

Did you find a way the doesn't involve including a whole new library?

timsonater commented 4 years ago

This worked for me, no libs

<TextInput
   style={{outline: "none"}}
/>
nandorojo commented 3 years ago
Screen Shot 2020-08-28 at 5 30 43 PM

I'm seeing this error when I do outline: none.

seancheung commented 3 years ago

This is a react native web issue rather than react-native-paper issue.

Here is a patch without a third-party library

import React from 'react';
import { Platform } from 'react-native';

export interface GlobalStyleProps {
  css: string;
}

const GlobalStyle: React.FC<GlobalStyleProps> = ({ css }) => {
  React.useEffect(() => {
    if (Platform.OS === 'web') {
      const style = document.createElement('style');
      style.textContent = css;
      document.head.append(style);
      return () => style.remove();
    }
  }, [css]);
  return null;
};

export default React.memo(GlobalStyle);

In your App.tsx:

<GlobalStyle css="input {outline: none;}" />

Note: This takes effects globally.

sanghee-dev commented 3 years ago

This worked for me!

import { Platform } from "react-native";

const TextInput = styled.TextInput`
  ${Platform.select({
    web: css`
      outline-style: none;
    `,
  })};
`;
minhquan1313 commented 3 weeks ago

if you use typescript

import { TextInput, TextInputProps } from "react-native";

<TextInput
  style={
    {
      outline: "none",
    } as TextInputProps["style"]
  }
  {..._props}
/>;

add as ... to disable error message :>